package com.ship.dispatch.service.report.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSON;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ship.common.business.service.impl.BaseServiceImpl;
import com.ship.common.core.constant.CacheConstants;
import com.ship.common.core.constant.ShipApiConstants;
import com.ship.common.core.exception.ServiceException;
import com.ship.common.core.utils.DateUtils;
import com.ship.common.core.utils.OkHttpUtil;
import com.ship.common.core.utils.StringUtils;
import com.ship.common.redis.service.RedisService;
import com.ship.common.security.utils.SecurityUtils;
import com.ship.dispatch.bean.*;
import com.ship.dispatch.bean.boats.info.QueryBoatsVoyageMessagesInfo;
import com.ship.dispatch.bean.orderPay.*;
import com.ship.dispatch.bean.report.ReportInfo;
import com.ship.dispatch.bean.report.ReportInfoWork;
import com.ship.dispatch.bean.report.ReportItem;
import com.ship.dispatch.bean.report.ReportItemWork;
import com.ship.dispatch.bean.sys.SysConstant;
import com.ship.dispatch.bean.treaShipNetwork.IhsShipBase;
import com.ship.dispatch.bo.ItemStatisticsSimpleBo;
import com.ship.dispatch.mapper.*;
import com.ship.dispatch.mapper.orderPay.*;
import com.ship.dispatch.mapper.report.ReportInfoMapper;
import com.ship.dispatch.mapper.report.ReportInfoWorkMapper;
import com.ship.dispatch.mapper.report.ReportItemMapper;
import com.ship.dispatch.mapper.report.ReportItemWorkMapper;
import com.ship.dispatch.mapper.sys.SysConstantMapper;
import com.ship.dispatch.mapper.treaShipNetwork.IhsShipBaseMapper;
import com.ship.dispatch.model.Vo.CanalTrafficInfo;
import com.ship.dispatch.model.dto.report.*;
import com.ship.dispatch.service.BoatsCanalAccessService;
import com.ship.dispatch.service.BoatsVoyageMessageService;
import com.ship.dispatch.service.SpArrangeSchemeDetailService;
import com.ship.dispatch.service.SpDispatchSchemeExecuteService;
import com.ship.dispatch.service.report.ReportItemService;
import com.ship.dispatch.service.treaShipNetwork.IhsShipBaseService;
import com.ship.dispatch.util.DateErgodicUtil;
import com.ship.dispatch.vo.report.*;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import org.apache.commons.collections4.map.HashedMap;
import org.apache.http.client.HttpClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.text.Collator;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

@Service
public class ReportItemServiceImpl extends BaseServiceImpl<ReportItemMapper, ReportItem> implements ReportItemService {
    private static final Logger logger = LoggerFactory.getLogger(ReportItemServiceImpl.class);

    @Autowired
    private SpArrangeSchemeDetailService spArrangeSchemeDetailService;

    @Autowired
    private ReportInfoMapper reportInfoMapper;

    @Autowired
    private ConResourceMainMapper conResourceMainMapper;
    @Autowired
    private ConResourceMemorandumMapper conResourceMemorandumMapper;
    @Autowired
    private ConShippingMapper conShippingMapper;
    @Autowired
    private ConShippingAgencyMapper conShippingAgencyMapper;
    @Autowired
    private ConBrokerMapper conBrokerMapper;
    @Autowired
    private ConThirdPartyMeasurementMapper conThirdPartyMeasurementMapper;
    @Autowired
    private ConInsuranceGoodsMapper conInsuranceGoodsMapper;
    @Autowired
    private ConInsurancePeopleMapper conInsurancePeopleMapper;
    @Autowired
    private ConRefuelingMapper conRefuelingMapper;
    @Autowired
    private ConLawyerMapper conLawyerMapper;
    @Autowired
    private SysConstantMapper constantMapper;
//    @Autowired
//    private IhsShipBaseMapper ihsShipBaseMapper;
    @Autowired
    private ReportInfoWorkMapper reportInfoWorkMapper;
    @Autowired
    private ReportItemWorkMapper reportItemWorkMapper;

    @Autowired
    private BoatsCanalAccessService boatsCanalAccessService;

    @Autowired
    private RedisService redisService;

    @Autowired
    private BoatsVoyageMessageService boatsVoyageMessageService;

    @Autowired
    private IhsShipBaseService ihsShipBaseService;

    /**
     * 根据不同展示类型选择不同数据接口
     *
     * @param typeId 1：数字，2：柱状，3：饼状，4：堆积图，5:双柱状图，6：单折线图，7：表格，8：多折线图,9：桑葚图
     * @return
     */
    @Override
    public List<DataContentByTypeVo> getDataContentByType(Integer typeId,String portName) {
        List<DataContentByTypeVo> dataContentByTypeVos = new ArrayList<>();
        if (typeId.equals(1)) {
            dataContentByTypeVos.add(new DataContentByTypeVo("待执行船货数量", "yearDispatchToExecuteGoodsCount"));
            dataContentByTypeVos.add(new DataContentByTypeVo("执行中船货数量", "yearDispatchGoingGoodsCount"));
            dataContentByTypeVos.add(new DataContentByTypeVo("已完成船货数量", "yearDispatchFinishGoodsCount"));
            dataContentByTypeVos.add(new DataContentByTypeVo("资源完成率", "yearDispatchArrangeFinishRate"));
            dataContentByTypeVos.add(new DataContentByTypeVo("已完成运输量", "yearDispatchArrangeFinishCount"));
            dataContentByTypeVos.add(new DataContentByTypeVo("年度资源采购量", "yearDispatchArrangeBuyCount"));
            dataContentByTypeVos.add(new DataContentByTypeVo("船货统计数量", "dispatchArrangeCount"));
            dataContentByTypeVos.add(new DataContentByTypeVo("合同数量统计", "contractAllTypeNums"));
            dataContentByTypeVos.add(new DataContentByTypeVo("资源合同-备忘录统计", "conResourceMemorandumTotal"));
            dataContentByTypeVos.add(new DataContentByTypeVo("资源合同-主合同统计", "conResourceMainTotal"));
            dataContentByTypeVos.add(new DataContentByTypeVo("船运合同统计", "conShippingTotal"));
        } else if (typeId.equals(2)) {
            dataContentByTypeVos.add(new DataContentByTypeVo("月度完成船货统计柱状图", "yearDispatchMonthFinishGoodsHistogram"));
            dataContentByTypeVos.add(new DataContentByTypeVo("年度船货统计分布柱状图", "yearDispatchArrangeHistogram"));
            dataContentByTypeVos.add(new DataContentByTypeVo("合同类型分布", "contractTypeDistribution"));
            dataContentByTypeVos.add(new DataContentByTypeVo("备忘录贸易类型分布", "conResourceMemorandumTradeType"));
            dataContentByTypeVos.add(new DataContentByTypeVo("备忘录类贸易模式分布", "conResourceMemorandumTradeModel"));
            dataContentByTypeVos.add(new DataContentByTypeVo("备忘录类贸易主体分布", "conResourceMemorandumTradeBody"));
            dataContentByTypeVos.add(new DataContentByTypeVo("备忘录交付方式分布", "conResourceMemorandumDeliveryType"));
            dataContentByTypeVos.add(new DataContentByTypeVo("备忘录状态分布", "conResourceMemorandumStatus"));
            dataContentByTypeVos.add(new DataContentByTypeVo("主合同贸易主体分布", "conResourceMainTradeBody"));
            dataContentByTypeVos.add(new DataContentByTypeVo("船运合同类型分布", "conShippingContractType"));
            dataContentByTypeVos.add(new DataContentByTypeVo("船运合同贸易主体分布", "conShippingTradeBody"));
            dataContentByTypeVos.add(new DataContentByTypeVo("船舶租入贸易主体分布", "conShippingRentTradeBody"));
            dataContentByTypeVos.add(new DataContentByTypeVo("LNG船舶状态分布", "lngShipStatus"));
            dataContentByTypeVos.add(new DataContentByTypeVo("LNG船舶船型分布", "lngShipTypeGroup"));
            dataContentByTypeVos.add(new DataContentByTypeVo("LNG船舶船龄分布", "lngShipYearOfBuild"));
            dataContentByTypeVos.add(new DataContentByTypeVo("LNG船舶主机类型分布", "lngShipMainEngineType"));
            dataContentByTypeVos.add(new DataContentByTypeVo("LNG船舶建造船厂分布", "lngShipbuilder"));
            dataContentByTypeVos.add(new DataContentByTypeVo("LNG船舶建造国家分布", "lngShipCountryOfBuild"));
            dataContentByTypeVos.add(new DataContentByTypeVo("LNG船舶船级社分布", "lngShipClassificationSociety"));
            dataContentByTypeVos.add(new DataContentByTypeVo("LNG船舶经营公司分布", "lngShipOperator"));
            dataContentByTypeVos.add(new DataContentByTypeVo("苏伊士运河通行量统计分布","statisticsCanalTraffic"));
            dataContentByTypeVos.add(new DataContentByTypeVo("巴拿马运河通行量统计分布","countPanamaCanalTraffic"));
            dataContentByTypeVos.add(new DataContentByTypeVo("世界LNG出口总量","shipExportVolumeTotal"));
            dataContentByTypeVos.add(new DataContentByTypeVo("排名前十的LNG出口港名称、出口量","shipPortExportVolume"));
            dataContentByTypeVos.add(new DataContentByTypeVo("排名前十的LNG进口港名称、进口量","shipPortEntranceVolume"));
            dataContentByTypeVos.add(new DataContentByTypeVo("月度国内到港LNG船舶航次数量","shipQuantityVoyage"));
            dataContentByTypeVos.add(new DataContentByTypeVo("世界月度LNG进口总量","shipEntranceVolumeTotal"));
        } else if (typeId.equals(3)) {
            dataContentByTypeVos.add(new DataContentByTypeVo("年度船货统计分布饼状图", "yearDispatchArrangePieChart"));
            dataContentByTypeVos.add(new DataContentByTypeVo("合同类型分布", "contractTypeDistribution"));
            dataContentByTypeVos.add(new DataContentByTypeVo("备忘录贸易类型分布", "conResourceMemorandumTradeType"));
            dataContentByTypeVos.add(new DataContentByTypeVo("备忘录类贸易模式分布", "conResourceMemorandumTradeModel"));
            dataContentByTypeVos.add(new DataContentByTypeVo("备忘录类贸易主体分布", "conResourceMemorandumTradeBody"));
            dataContentByTypeVos.add(new DataContentByTypeVo("备忘录交付方式分布", "conResourceMemorandumDeliveryType"));
            dataContentByTypeVos.add(new DataContentByTypeVo("备忘录状态分布", "conResourceMemorandumStatus"));
            dataContentByTypeVos.add(new DataContentByTypeVo("船运合同类型分布", "conShippingContractType"));
            dataContentByTypeVos.add(new DataContentByTypeVo("船运合同贸易主体分布", "conShippingTradeBody"));
            dataContentByTypeVos.add(new DataContentByTypeVo("船舶租入贸易主体分布", "conShippingRentTradeBody"));
            dataContentByTypeVos.add(new DataContentByTypeVo("LNG船舶状态分布", "lngShipStatus"));
            dataContentByTypeVos.add(new DataContentByTypeVo("LNG船舶船型分布", "lngShipTypeGroup"));
            dataContentByTypeVos.add(new DataContentByTypeVo("LNG船舶船龄分布", "lngShipYearOfBuild"));
            dataContentByTypeVos.add(new DataContentByTypeVo("LNG船舶主机类型分布", "lngShipMainEngineType"));
            dataContentByTypeVos.add(new DataContentByTypeVo("LNG船舶建造船厂分布", "lngShipbuilder"));
            dataContentByTypeVos.add(new DataContentByTypeVo("LNG船舶建造国家分布", "lngShipCountryOfBuild"));
            dataContentByTypeVos.add(new DataContentByTypeVo("LNG船舶船级社分布", "lngShipClassificationSociety"));
            dataContentByTypeVos.add(new DataContentByTypeVo("LNG船舶经营公司分布", "lngShipOperator"));
        } else if (typeId.equals(4)) {
            dataContentByTypeVos.add(new DataContentByTypeVo("不同类型备忘录状态分布", "memorandumTypeStatus"));
            dataContentByTypeVos.add(new DataContentByTypeVo("船运合同类型及贸易主体分布", "conShippingContractTypeAndTradeBody"));
            dataContentByTypeVos.add(new DataContentByTypeVo("船运合同类型及状态分布", "conShippingContractTypeAndStatus"));
            dataContentByTypeVos.add(new DataContentByTypeVo("世界月度LNG出口量（按国家）", "shipExportVolumeTotalByCountryName"));
            dataContentByTypeVos.add(new DataContentByTypeVo("世界月度LNG进口量（按照国家）","shipEntranceVolumeTotalByCountryName"));
        } else if (typeId.equals(5)) {
            dataContentByTypeVos.add(new DataContentByTypeVo("船运合同类型及贸易主体分布", "conShippingContractTypeAndTradeBody"));
        } else if (typeId.equals(6)) {
            dataContentByTypeVos.add(new DataContentByTypeVo("月度完成船货统计折线图", "yearDispatchMonthFinishGoodsLineChart"));
            dataContentByTypeVos.add(new DataContentByTypeVo("贸易利润率趋势图", "yearDispatchTradeGetStatistics"));
        } else if (typeId.equals(7)) {
            dataContentByTypeVos.add(new DataContentByTypeVo("月度国内到港LNG船舶航次", "monthlyDomesticVesselVoyage"));
        } else if (typeId.equals(8)) {
            dataContentByTypeVos.add(new DataContentByTypeVo("船舶租金折线图（现货西航线）", "shipRentNowWestLineChart"));
            dataContentByTypeVos.add(new DataContentByTypeVo("船舶租金折线图（现货东航线）", "shipRentNowEastLineChart"));
            dataContentByTypeVos.add(new DataContentByTypeVo("船舶租金折线图（六个月中长期）", "shipRentSixLineChart"));
            dataContentByTypeVos.add(new DataContentByTypeVo("船舶租金折线图（十二个月中长期）", "shipRentTwelveLineChart"));
            dataContentByTypeVos.add(new DataContentByTypeVo("船舶租金折线图（三十六个月中长期）", "shipRentThirtySixLineChart"));
        }else if (typeId.equals(9)){
            dataContentByTypeVos.add(new DataContentByTypeVo("月度到中国LNG流向", "queryVoyageNumber"));
            dataContentByTypeVos.add(new DataContentByTypeVo("月度到海油LNG流向", "queryMonthlyVoyageNumber"));
        }
        List<DataContentByTypeVo> resultLst = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(dataContentByTypeVos)){
            if (StringUtils.isNotEmpty(portName)){
                resultLst = dataContentByTypeVos.stream().filter(DataContentByTypeVo -> DataContentByTypeVo.getName().contains(portName)).collect(Collectors.toList());
            }else {
                resultLst.addAll(dataContentByTypeVos);
            }
            resultLst.sort((o1,o2) -> {
                Comparator<Object> com = Collator.getInstance(Locale.CHINA);
                return com.compare(o1.getName(), o2.getName());
            });
        }
        return resultLst;
    }

    /**
     * 保存统计报表渲染表
     *
     * @param reportItem
     * @return
     */
    @Override
    public ReportItem saveReportItem(ReportItem reportItem) {
        reportItem.setCreateBy(SecurityUtils.getStringUserId());
        reportItem.setCreateDate(new Date());
        this.save(reportItem);
        return reportItem;
    }

    /**
     * 查询统计报表渲染表
     *
     * @return
     */
    @Override
    public List<ReportItem> selectReportItems() {
        List<ReportItem> reportItems = new ArrayList<>();

        List<ReportInfo> reportInfos = reportInfoMapper.selectList(new LambdaQueryWrapper<ReportInfo>()
                .eq(ReportInfo::getCreateBy, SecurityUtils.getStringUserId()));
        if (null != reportInfos && reportInfos.size() > 0) {
            List<ReportItem> reportAllItems = this.list();
            if (reportAllItems.size() > 0) {
                List<ReportItem> finalReportItems = reportItems;
                reportAllItems.stream().forEach(r -> {
                    if (reportInfos.stream().filter(s -> s.getReportId().equals(r.getId())).count() <= 0) {
                        finalReportItems.add(r);
                    }
                });
                reportItems.addAll(finalReportItems);
            }
        } else {
            reportItems = this.list();
        }
        return reportItems;
    }

    /**
     * 添加图表接口
     *
     * @param reportItemDto
     * @return
     */
    @Override
    public void saveReportInfo(ReportItemDto reportItemDto) {
        ReportItem reportItem = new ReportItem();
        reportItem.setWorkbench(2);
        reportItem.setCreateBy(SecurityUtils.getStringUserId());
        reportItem.setCreateDate(new Date());
        reportItem.setDataSourceType(1);
        BeanUtils.copyProperties(reportItemDto, reportItem);
        long time = System.currentTimeMillis();

        String redisKey = reportItemDto.getDataSource() +"-"+ time;
        reportItem.setDataSource(redisKey);
        this.save(reportItem);
        ReportInfo reportInfo = new ReportInfo();
        reportInfo.setReportId(reportItem.getId());
        reportInfo.setCreateBy(SecurityUtils.getStringUserId());
        reportInfo.setCreateDate(new Date());
//        reportInfo.setChartNum(reportItemDto.getChartNum());
//        reportInfo.setChartSort(reportItemDto.getChartSort());
        reportInfo.setWNum("2.8");
        reportInfo.setHNum("2.6");
        reportInfo.setStaticValue("false");

        ReportInfo reportInfoNew = reportInfoMapper.selectOne(new LambdaQueryWrapper<ReportInfo>()
                .eq(ReportInfo::getCreateBy, SecurityUtils.getStringUserId())
                .orderByDesc(ReportInfo::getCreateDate)
                .last("limit 1"));
        if (null == reportInfoNew) {
            reportInfo.setXNum(0);
            reportInfo.setYNum(0);
            reportInfo.setINum(0);
        } else {
            if (reportInfoNew.getXNum().equals(9)) {
                reportInfo.setXNum(0);
                reportInfo.setYNum(reportInfoNew.getYNum() + 1);
            } else {
                reportInfo.setXNum(reportInfoNew.getXNum() + 3);
                reportInfo.setYNum(reportInfoNew.getYNum());
            }
            reportInfo.setINum(reportInfoNew.getINum() + 1);
        }
        reportInfoMapper.insert(reportInfo);
        //删除缓存
        redisService.deleteObject(CacheConstants.DATA_BOARD_INFO_KEY+SecurityUtils.getStringUserId()+":"+reportItem.getDataSource());
    }

    /**
     * 删除图表接口
     *
     * @param id
     */
    @Override
    public void removeReportInfo(Long id) {
        ReportInfo reportInfo = reportInfoMapper.selectById(id);
        if (null != reportInfo) {
            reportInfoMapper.deleteById(id);
        }
    }

    @Override
    public void reportItemCacheUpdate() {
        //获取所有配置了图表数据得用户id
        List<ReportInfo> reportUids = reportInfoMapper.selectList(new LambdaQueryWrapper<ReportInfo>().groupBy(ReportInfo::getCreateBy));
        if(reportUids.size() == 0){
            return;
        }
        for (ReportInfo report : reportUids) {
            String userId = report.getCreateBy();
            redisService.deleteByPrefix(CacheConstants.DATA_BOARD_INFO_KEY+userId+":*");
            ReportInfoDto reportInfoDto = new ReportInfoDto();
            reportInfoDto.setDataType(1);
            reportInfoDto.setUserId(userId);
            this.selectReportInfos(reportInfoDto);
        }
    }

    @Override
    public List<DataContentByTypeVo> getDataSourceInfo(String sourceName) {
        return this.baseMapper.getDataSourceInfo(sourceName);
    }

    @Override
    public List<DataContentByTypeVo> getTableTypeBySource(String sourceName) {
        return this.baseMapper.getTableTypeBySource(sourceName);
    }

    /**
     * 查看图表接口
     *
     * @return
     */
    @Override
    public List<ReportInfoVo> selectReportInfos(ReportInfoDto reportInfoDto) {
        if(reportInfoDto.getUserId() == null){
            reportInfoDto.setUserId(SecurityUtils.getStringUserId());
        }

        List<ReportInfoVo> finalReportInfoVos = new ArrayList<>();
        List<ReportInfo> reportInfos = reportInfoMapper.selectList(new LambdaQueryWrapper<ReportInfo>()
                .eq(ReportInfo::getCreateBy, reportInfoDto.getUserId()));
        try{
            for (ReportInfo reportInfo : reportInfos) {
                ReportInfoVo reportInfoVo = new ReportInfoVo();
                BeanUtils.copyProperties(reportInfo, reportInfoVo);
                ReportItem reportItem = this.getById(reportInfo.getReportId());
                if (null != reportItem) {
                    reportInfoVo.setChartName(reportItem.getChartName());
                    reportInfoVo.setChartType(reportItem.getChartType());
                    reportInfoVo.setDataSourceType(reportItem.getDataSourceType());
                    reportInfoVo.setDataSource(reportItem.getDataSource());
                    reportInfoVo.setChartSetting(reportItem.getChartSetting());
                    reportInfoVo.setWorkbench(reportItem.getWorkbench());
                    reportInfoVo.setThemeColor(reportItem.getThemeColor());
                    reportInfoVo.setChartElement(reportItem.getChartElement());
                    reportInfoVo.setStatisValueFormat(reportItem.getStatisValueFormat());
                    reportInfoVo.setDateType(reportItem.getDateType());
                    reportInfoVo.setStartDate(reportItem.getStartDate());
                    reportInfoVo.setEndDate(reportItem.getEndDate());
                }
                finalReportInfoVos.add(reportInfoVo);
            }
            Boolean isAll = reportInfoDto.getStartTime() == null && reportInfoDto.getEndTime() == null ? true : false;
            //根据数据源信息拉取相关接口,区分全局查询还是个别查询
            if (reportInfoDto.getDataType().equals(1)) {
                //全局查询
                if (finalReportInfoVos.size() > 0) {
                    for (ReportInfoVo finalReportInfoVo : finalReportInfoVos) {
                        ReportItem reportItem = this.getById(finalReportInfoVo.getReportId());
                        if (null != reportItem) {
                            Object object = null;
                            if(isAll){
                                //先从redis里面取，取不到再实时查询
                                object = redisService.getCacheObject(CacheConstants.DATA_BOARD_INFO_KEY+reportInfoDto.getUserId()+":"+reportItem.getDataSource());
                            }
                            String dataSource = reportItem.getDataSource().split("-")[0];
                            finalReportInfoVo.setDataSource(dataSource);
                            if(object == null){
                                //根据时间类型来组装时间参数
                                if(reportItem.getDateType().intValue() == 0){
                                    Date endDate = reportItem.getEndDate();
                                    Date startDate = reportItem.getStartDate();
                                    object = this.getTypeContent(dataSource, startDate, endDate);
                                }else{
                                    Date endDate = new Date();
                                    Date startDate = getStartDate(endDate,finalReportInfoVo.getDateType());
                                    object = this.getTypeContent(dataSource, startDate, endDate);
                                }

                                if(isAll){
                                    //刷新缓存信息
                                    redisService.setCacheObject(CacheConstants.DATA_BOARD_INFO_KEY+reportInfoDto.getUserId()+":"+reportItem.getDataSource()
                                            ,object,CacheConstants.DATA_BOARD_REFRESH_TIME,TimeUnit.MINUTES);
                                }
                            }
                            finalReportInfoVo.setDataObject(object);
                        }
                    }
                }
            } else if (reportInfoDto.getDataType().equals(2)) {
                //个别查询
                if (finalReportInfoVos.size() > 0) {
                    finalReportInfoVos = finalReportInfoVos.stream().filter(s -> s.getDataSource().equals(reportInfoDto.getDataSource())).collect(Collectors.toList());
                    if (finalReportInfoVos.size() > 0) {
                        if(finalReportInfoVos.get(0).getDateType().intValue() == 0){
                            Date endDate = finalReportInfoVos.get(0).getEndDate();
                            Date startDate = finalReportInfoVos.get(0).getStartDate();
                            Object object = this.getTypeContent(reportInfoDto.getDataSource(), startDate, endDate);
                            finalReportInfoVos.get(0).setDataObject(object);
                        }else{
                            Date endDate = new Date();
                            Date startDate = getStartDate(endDate,finalReportInfoVos.get(0).getDateType());
                            Object object = this.getTypeContent(reportInfoDto.getDataSource(), startDate, endDate);
                            finalReportInfoVos.get(0).setDataObject(object);
                        }

                    }
                }
            }
        }catch (Exception ex){
            System.out.println("selectReportInfos数据看板查询方法报错："+ex.getMessage());
        }
        return finalReportInfoVos;
    }

    /**
     * 获取开始时间
     * @param endDate
     * @param dateType
     * @return
     */
    public Date getStartDate(Date endDate,int dateType){
        Date startDate = endDate;
        if(dateType == 1){
            startDate = DateUtil.offsetDay(endDate,-7);
        } else if(dateType == 2){
            startDate = DateUtil.offsetMonth(endDate,-1);
        } else if(dateType == 3){
            startDate = DateUtil.offsetMonth(endDate,-3);
        }else if(dateType == 4){
            startDate = DateUtil.offsetMonth(endDate,-6);
        }else if(dateType == 5){
            startDate = DateUtil.offsetMonth(endDate,-12);
        }
        return startDate;
    }

    /**
     * 根据数据源获取相关数据
     *
     * @param dto
     * @return
     */
    @Override
    public Object getDataContentByKey(getReportDataInfoDto dto) throws ParseException {
        Object object = new Object();
        if(dto.getDateType() != null && dto.getDateType().intValue() == 0){
            Date endDate = dto.getEndDate();
            Date startDate = dto.getStartDate();
            object = this.getTypeContent(dto.getType(), startDate, endDate);
        }else{
            Date endDate = new Date();
            Date startDate = getStartDate(endDate,dto.getDateType());

            object = this.getTypeContent(dto.getType(), startDate, endDate);
        }
        return object;
    }

    private Object getTypeContent(String type, Date startTime, Date endTime) throws ParseException {
        Object object = new Object();
        ItemStatisticsSimpleBo bo = new ItemStatisticsSimpleBo();
        bo.setStartTime(startTime);
        bo.setEndTime(endTime);
        switch (type) {
            case "shipRentNowWestLineChart":
                object = spArrangeSchemeDetailService.shipRentNowWestLineChart(bo);
                break;
            case "yearDispatchMonthFinishGoodsLineChart":
                object = spArrangeSchemeDetailService.yearDispatchMonthFinishGoodsLineChart(bo);
                break;
            case "yearDispatchMonthFinishGoodsHistogram":
                object = spArrangeSchemeDetailService.yearDispatchMonthFinishGoodsHistogram(bo);
                break;
            case "yearDispatchToExecuteGoodsCount":
                object = spArrangeSchemeDetailService.yearDispatchToExecuteGoodsCount(bo);
                break;
            case "yearDispatchGoingGoodsCount":
                object = spArrangeSchemeDetailService.yearDispatchGoingGoodsCount(bo);
                break;
            case "yearDispatchFinishGoodsCount":
                object = spArrangeSchemeDetailService.yearDispatchFinishGoodsCount(bo);
                break;
            case "yearDispatchTradeGetStatistics":
                object = spArrangeSchemeDetailService.yearDispatchTradeGetStatistics(bo);
                break;
            case "monthlyDomesticVesselVoyage":
                object = boatsVoyageMessageService.monthlyDomesticVesselVoyage(bo);
                break;
            case "queryVoyageNumber":
                object = boatsVoyageMessageService.queryVoyageNumber(bo);
                break;
            case "queryMonthlyVoyageNumber":
                object = boatsVoyageMessageService.queryMonthlyVoyageNumber(bo);
                break;
            case "yearDispatchShipDayLineChart":
                object = spArrangeSchemeDetailService.yearDispatchShipDayLineChart(bo);
                break;
            case "yearDispatchShipHistogram":
                object = spArrangeSchemeDetailService.yearDispatchShipHistogram(bo);
                break;
            case "yearDispatchShipStatisticsPieChart":
                object = spArrangeSchemeDetailService.yearDispatchShipStatisticsPieChart(bo);
                break;
            case "yearDispatchShipStatisticsHistogram":
                object = spArrangeSchemeDetailService.yearDispatchShipStatisticsHistogram(bo);
                break;
            case "shipRentNowEastLineChart":
                object = spArrangeSchemeDetailService.shipRentNowEastLineChart(bo);
                break;
            case "shipRentSixLineChart":
                object = spArrangeSchemeDetailService.shipRentSixLineChart(bo);
                break;
            case "shipRentTwelveLineChart":
                object = spArrangeSchemeDetailService.shipRentTwelveLineChart(bo);
                break;
            case "shipRentThirtySixLineChart":
                object = spArrangeSchemeDetailService.shipRentThirtySixLineChart(bo);
                break;
            case "dispatchArrangeCount":
                object = spArrangeSchemeDetailService.dispatchArrangeCount(bo);
                break;
            case "yearDispatchArrangePieChart":
                object = spArrangeSchemeDetailService.yearDispatchArrangePieChart(bo);
                break;
            case "yearDispatchArrangeHistogram":
                object = spArrangeSchemeDetailService.yearDispatchArrangeHistogram(bo);
                break;
            case "yearDispatchArrangeBuyCount":
                object = spArrangeSchemeDetailService.yearDispatchArrangeBuyCount(bo);
                break;
            case "yearDispatchArrangeFinishCount":
                object = spArrangeSchemeDetailService.yearDispatchArrangeFinishCount(bo);
                break;
            case "yearDispatchArrangeFinishRate":
                object = spArrangeSchemeDetailService.yearDispatchArrangeFinishRate(bo);
                break;
            case "contractAllTypeNums":
                object = this.contractAllTypeNums(bo);
                break;
            case "contractTypeDistribution":
                object = this.contractTypeDistribution(bo);
                break;
            case "conResourceMemorandumTotal":
                object = this.conResourceMemorandumTotal(bo);
                break;
            case "statisticsCanalTraffic":
                object = this.statisticsCanalTraffic(bo);
                break;
            case "countPanamaCanalTraffic":
                object = this.countPanamaCanalTraffic(bo);
                break;
            case "shipExportVolumeTotal":
                object = this.shipExportVolumeTotal(bo);
                break;
            case "shipEntranceVolumeTotal":
                object = this.shipEntranceVolumeTotal(bo);
                break;
            case "shipPortExportVolume":
                object = this.shipPortExportVolume(bo);
                break;
            case "shipPortEntranceVolume":
                object = this.shipPortEntranceVolume(bo);
                break;
            case "shipQuantityVoyage":
                object = this.shipQuantityVoyage(bo);
                break;
            case "conResourceMainTotal":
                object = this.conResourceMainTotal(bo);
                break;
            case "conResourceMemorandumTradeType":
                object = this.conResourceMemorandumTradeType(bo);
                break;
            case "conResourceMemorandumTradeModel":
                object = this.conResourceMemorandumTradeModel(bo);
                break;
            case "conResourceMemorandumTradeBody":
                object = this.conResourceMemorandumTradeBody(bo);
                break;
            case "conResourceMemorandumDeliveryType":
                object = this.conResourceMemorandumDeliveryType(bo);
                break;
            case "conResourceMemorandumStatus":
                object = this.conResourceMemorandumStatus(bo);
                break;
            case "conResourceMainTradeBody":
                object = this.conResourceMainTradeBody(bo);
                break;
            case "conShippingTotal":
                object = this.conShippingTotal(bo);
                break;
            case "conShippingContractType":
                object = this.conShippingContractType(bo);
                break;
            case "memorandumTypeStatus":
                object = this.memorandumTypeStatus(bo);
                break;
            case "conShippingTradeBody":
                object = this.conShippingTradeBody(bo);
                break;
            case "conShippingRentTradeBody":
                object = this.conShippingRentTradeBody(bo);
                break;
            case "conShippingContractTypeAndTradeBody":
                object = this.conShippingContractTypeAndTradeBody(bo);
                break;
            case "conShippingContractTypeAndStatus":
                object = this.conShippingContractTypeAndStatus(bo);
                break;
            case "shipExportVolumeTotalByCountryName":
                object = this.shipExportVolumeTotalByCountryName(bo);
                break;
            case "shipEntranceVolumeTotalByCountryName":
                object = this.shipEntranceVolumeTotalByCountryName(bo);
                break;
            case "lngShipStatus":
                object = this.lngShipStatus(bo);
                break;
            case "lngShipTypeGroup":
                object = this.lngShipTypeGroup(bo);
                break;
            case "lngShipYearOfBuild":
                object = this.lngShipYearOfBuild(bo);
                break;
            case "lngShipMainEngineType":
                object = this.lngShipMainEngineType(bo);
                break;
            case "lngShipbuilder":
                object = this.lngShipbuilder(bo);
                break;
            case "lngShipCountryOfBuild":
                object = this.lngShipCountryOfBuild(bo);
                break;
            case "lngShipClassificationSociety":
                object = this.lngShipClassificationSociety(bo);
                break;
            case "lngShipOperator":
                object = this.lngShipOperator(bo);
                break;
            default:
                break;
        }
        return object;
    }


    private Object shipQuantityVoyage(ItemStatisticsSimpleBo bo) {
        List<ShapeUnifyVo> shapeUnifyVos = new ArrayList<>();
        JSONObject jsonObject = new JSONObject();
        String startDate = DateUtil.format(bo.getStartTime(), DatePattern.NORM_DATE_FORMATTER);
        String endDate = DateUtil.format(bo.getEndTime(), DatePattern.NORM_DATE_FORMATTER);
        List<QueryBoatsVoyageMessagesInfo> portList = boatsVoyageMessageService.shipQuantityVoyage(startDate,endDate);
        if (CollectionUtil.isNotEmpty(portList)){
            portList.forEach(item -> {
                ShapeUnifyVo shapeUnifyVo = new ShapeUnifyVo();
                shapeUnifyVo.setKey(item.getPortName());
                shapeUnifyVo.setValue(item.getExportVolumeTotal().toString());
                shapeUnifyVos.add(shapeUnifyVo);
            });
        }
        jsonObject.put("dataList", shapeUnifyVos);
        return jsonObject;
    }

    private Object shipPortEntranceVolume(ItemStatisticsSimpleBo bo) {
        List<ShapeUnifyVo> shapeUnifyVos = new ArrayList<>();
        JSONObject jsonObject = new JSONObject();
        String startDate = DateUtil.format(bo.getStartTime(), DatePattern.NORM_DATE_FORMATTER);
        String endDate = DateUtil.format(bo.getEndTime(), DatePattern.NORM_DATE_FORMATTER);
        List<QueryBoatsVoyageMessagesInfo> portList = boatsVoyageMessageService.queryhipPortEntranceVolume(startDate,endDate);
        if (CollectionUtil.isNotEmpty(portList)){
            portList.forEach(item -> {
                ShapeUnifyVo shapeUnifyVo = new ShapeUnifyVo();
                shapeUnifyVo.setKey(item.getPortName());
                shapeUnifyVo.setValue(item.getExportVolumeTotal().toString());
                shapeUnifyVos.add(shapeUnifyVo);
            });
        }
        jsonObject.put("dataList", shapeUnifyVos);
        return jsonObject;
    }

    /**
     * 排名前十的LNG出口港名称、出口量
     * @param bo
     * @return
     */
    private Object shipPortExportVolume(ItemStatisticsSimpleBo bo) {
        List<ShapeUnifyVo> shapeUnifyVos = new ArrayList<>();
        JSONObject jsonObject = new JSONObject();
        String startDate = DateUtil.format(bo.getStartTime(), DatePattern.NORM_DATE_FORMATTER);
        String endDate = DateUtil.format(bo.getEndTime(), DatePattern.NORM_DATE_FORMATTER);
        List<QueryBoatsVoyageMessagesInfo> portList = boatsVoyageMessageService.queryShipPortExportVolume(startDate,endDate);
        List<String> dateList = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(portList)){
            portList.forEach(item -> {
                ShapeUnifyVo shapeUnifyVo = new ShapeUnifyVo();
                shapeUnifyVo.setKey(item.getPortName());
                shapeUnifyVo.setValue(item.getExportVolumeTotal().toString());
                shapeUnifyVos.add(shapeUnifyVo);
            });
        }
        jsonObject.put("dataList", shapeUnifyVos);
        return jsonObject;
    }

    /**
     * 世界月度LNG出口量（按照国家）
     * @param bo
     * @return
     */
    private Object shipExportVolumeTotalByCountryName(ItemStatisticsSimpleBo bo) {
        JSONObject jsonObject = new JSONObject();
        List<StackedDiagramVo> stackedDiagramVos = new ArrayList<>();
        String startDate = DateUtil.format(bo.getStartTime(), DatePattern.NORM_DATE_FORMATTER);
        String endDate = DateUtil.format(bo.getEndTime(), DatePattern.NORM_DATE_FORMATTER);
        List<QueryBoatsVoyageMessagesInfo> boatsVoyageMessages = boatsVoyageMessageService.queryShipExportVolumeTotal(startDate,endDate);
        if (CollectionUtil.isNotEmpty(boatsVoyageMessages)){
            boatsVoyageMessages.forEach(item -> {
                StackedDiagramVo stackedDiagramVo = new StackedDiagramVo();
                stackedDiagramVo.setName(item.getTotalDate());
                List<QueryBoatsVoyageMessagesInfo> list = boatsVoyageMessageService.shipExportVolumeTotalByCountryName(item.getTotalDate());
                if (CollectionUtil.isNotEmpty(list)){
                    List<StackedDiagramItemVo> diagramItemVos = new ArrayList<>();
                    if (list.size() > 10){
                        BigDecimal bigDecimal = new BigDecimal(0);
                        for (int i = 0; i < list.size(); i++) {
                            if (i>=10){
                                bigDecimal = bigDecimal.add(new BigDecimal(list.get(i).getExportVolumeTotal().toString()));
                            }else {
                                StackedDiagramItemVo stackedDiagramItemVo = new StackedDiagramItemVo();
                                stackedDiagramItemVo.setKey(list.get(i).getLoadCountry());
                                stackedDiagramItemVo.setValue(list.get(i).getExportVolumeTotal().toString());
                                diagramItemVos.add(stackedDiagramItemVo);
                            }
                        }
                        StackedDiagramItemVo stackedDiagramItemVo = new StackedDiagramItemVo();
                        stackedDiagramItemVo.setKey("others");
                        stackedDiagramItemVo.setValue(String.valueOf(bigDecimal));
                        diagramItemVos.add(stackedDiagramItemVo);
                    }else {
                        list.forEach(value -> {
                            StackedDiagramItemVo stackedDiagramItemVo = new StackedDiagramItemVo();
                            stackedDiagramItemVo.setKey(value.getLoadCountry());
                            stackedDiagramItemVo.setValue(value.getExportVolumeTotal().toString());
                            diagramItemVos.add(stackedDiagramItemVo);
                        });
                    }
                    stackedDiagramVo.setList(diagramItemVos);
                }
                stackedDiagramVos.add(stackedDiagramVo);
            });
        }
        jsonObject.put("dataList", stackedDiagramVos);
        return jsonObject;
    }

    private Object shipEntranceVolumeTotalByCountryName(ItemStatisticsSimpleBo bo) {
        JSONObject jsonObject = new JSONObject();
        List<StackedDiagramVo> stackedDiagramVos = new ArrayList<>();
        String startDate = DateUtil.format(bo.getStartTime(), DatePattern.NORM_DATE_FORMATTER);
        String endDate = DateUtil.format(bo.getEndTime(), DatePattern.NORM_DATE_FORMATTER);
        List<QueryBoatsVoyageMessagesInfo> boatsVoyageMessages = boatsVoyageMessageService.shipEntranceVolumeTotal(startDate,endDate);
        if (CollectionUtil.isNotEmpty(boatsVoyageMessages)){
            boatsVoyageMessages.forEach(item -> {
                StackedDiagramVo stackedDiagramVo = new StackedDiagramVo();
                stackedDiagramVo.setName(item.getTotalDate());
                List<QueryBoatsVoyageMessagesInfo> list = boatsVoyageMessageService.shipEntranceVolumeTotalByCountryName(item.getTotalDate());
                if (CollectionUtil.isNotEmpty(list)){
                    List<StackedDiagramItemVo> diagramItemVos = new ArrayList<>();
                    if (list.size() > 10){
                        BigDecimal bigDecimal = new BigDecimal(0);
                        for (int i = 0; i < list.size(); i++) {
                            if (i>=10){
                                bigDecimal = bigDecimal.add(new BigDecimal(list.get(i).getExportVolumeTotal().toString()));
                            }else {
                                StackedDiagramItemVo stackedDiagramItemVo = new StackedDiagramItemVo();
                                stackedDiagramItemVo.setKey(list.get(i).getLoadCountry());
                                stackedDiagramItemVo.setValue(list.get(i).getExportVolumeTotal().toString());
                                diagramItemVos.add(stackedDiagramItemVo);
                            }
                        }
                        StackedDiagramItemVo stackedDiagramItemVo = new StackedDiagramItemVo();
                        stackedDiagramItemVo.setKey("others");
                        stackedDiagramItemVo.setValue(String.valueOf(bigDecimal));
                        diagramItemVos.add(stackedDiagramItemVo);
                    }else {
                        list.forEach(value -> {
                            StackedDiagramItemVo stackedDiagramItemVo = new StackedDiagramItemVo();
                            stackedDiagramItemVo.setKey(value.getLoadCountry());
                            stackedDiagramItemVo.setValue(value.getExportVolumeTotal().toString());
                            diagramItemVos.add(stackedDiagramItemVo);
                        });
                    }
                    stackedDiagramVo.setList(diagramItemVos);
                }
                stackedDiagramVos.add(stackedDiagramVo);
            });
        }

        jsonObject.put("dataList", stackedDiagramVos);
        return jsonObject;
    }

    /**
     * 世界LNG出口总量
     * @param bo
     * @return
     */
    private Object shipExportVolumeTotal(ItemStatisticsSimpleBo bo) throws ParseException {
        List<ShapeUnifyVo> shapeUnifyVos = new ArrayList<>();
        JSONObject jsonObject = new JSONObject();
        String startDate = DateUtil.format(bo.getStartTime(), DatePattern.NORM_DATE_FORMATTER);
        String endDate = DateUtil.format(bo.getEndTime(), DatePattern.NORM_DATE_FORMATTER);
        List<QueryBoatsVoyageMessagesInfo> boatsVoyageMessages = boatsVoyageMessageService.queryShipExportVolumeTotal(startDate,endDate);
        List<String> dateList = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(boatsVoyageMessages)) {
            if (StringUtils.isNotEmpty(startDate) && StringUtils.isNotEmpty(endDate)){
                dateList = DateErgodicUtil.dateErgodicUtil(startDate, endDate);
                Map<String, List<QueryBoatsVoyageMessagesInfo>> map = boatsVoyageMessages.stream().collect(Collectors.groupingBy(QueryBoatsVoyageMessagesInfo::getTotalDate));
                dateList.forEach(item -> {
                    ShapeUnifyVo shapeUnifyVo = new ShapeUnifyVo();
                    shapeUnifyVo.setKey(item);
                    if (CollectionUtil.isNotEmpty(map.get(item))) {
                        if (map.get(item).get(0).getExportVolumeTotal() != null) {
                            shapeUnifyVo.setValue(map.get(item).get(0).getExportVolumeTotal().toString());
                        } else {
                            shapeUnifyVo.setValue(new BigDecimal(0).toString());
                        }
                    }else {
                        shapeUnifyVo.setValue(new BigDecimal(0).toString());
                    }
                    shapeUnifyVos.add(shapeUnifyVo);
                });
            }else {
                boatsVoyageMessages.forEach(item -> {
                    ShapeUnifyVo shapeUnifyVo = new ShapeUnifyVo();
                    shapeUnifyVo.setKey(item.getTotalDate());
                    if (item.getExportVolumeTotal() != null) {
                        shapeUnifyVo.setValue(item.getExportVolumeTotal().toString());
                    } else {
                        shapeUnifyVo.setValue(new BigDecimal(0).toString());
                    }
                    shapeUnifyVos.add(shapeUnifyVo);
                });
            }

        }
        jsonObject.put("dataList", shapeUnifyVos);
        return jsonObject;
    }

    /**
     * 世界月度LNG进口总量
     * @param bo
     * @return
     */
    private Object shipEntranceVolumeTotal(ItemStatisticsSimpleBo bo) throws ParseException {
        List<ShapeUnifyVo> shapeUnifyVos = new ArrayList<>();
        JSONObject jsonObject = new JSONObject();
        String startDate = DateUtil.format(bo.getStartTime(), DatePattern.NORM_DATE_FORMATTER);
        String endDate = DateUtil.format(bo.getEndTime(), DatePattern.NORM_DATE_FORMATTER);
        List<QueryBoatsVoyageMessagesInfo> boatsVoyageMessages = boatsVoyageMessageService.shipEntranceVolumeTotal(startDate,endDate);
        List<String> dateList = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(boatsVoyageMessages)){
            if (StringUtils.isNotEmpty(startDate) && StringUtils.isNotEmpty(endDate)){
                dateList = DateErgodicUtil.dateErgodicUtil(startDate, endDate);
                Map<String, List<QueryBoatsVoyageMessagesInfo>> map = boatsVoyageMessages.stream().collect(Collectors.groupingBy(QueryBoatsVoyageMessagesInfo::getTotalDate));
                dateList.forEach(item -> {
                    ShapeUnifyVo shapeUnifyVo = new ShapeUnifyVo();
                    shapeUnifyVo.setKey(item);
                    if (CollectionUtil.isNotEmpty(map.get(item))) {
                        if (map.get(item).get(0).getExportVolumeTotal() != null) {
                            shapeUnifyVo.setValue(map.get(item).get(0).getExportVolumeTotal().toString());
                        } else {
                            shapeUnifyVo.setValue(new BigDecimal(0).toString());
                        }
                    }else {
                        shapeUnifyVo.setValue(new BigDecimal(0).toString());
                    }
                    shapeUnifyVos.add(shapeUnifyVo);
                });
            }else {
                boatsVoyageMessages.forEach(item -> {
                    ShapeUnifyVo shapeUnifyVo = new ShapeUnifyVo();
                    shapeUnifyVo.setKey(item.getTotalDate());
                    if (item.getExportVolumeTotal() != null) {
                        shapeUnifyVo.setValue(item.getExportVolumeTotal().toString());
                    } else {
                        shapeUnifyVo.setValue(new BigDecimal(0).toString());
                    }
                    shapeUnifyVos.add(shapeUnifyVo);
                });
            }

        }
        jsonObject.put("dataList", shapeUnifyVos);
        return jsonObject;
    }

    /**
     * 更新图表接口(拖动更新)
     *
     * @return
     */
    @Override
    public void updateReportInfo(List<UpdateReportInfoDto> updateReportInfoDtos) {
        //List<ReportInfoVo> reportInfoVos = new ArrayList<>();
        if (null != updateReportInfoDtos && updateReportInfoDtos.size() > 0) {
            updateReportInfoDtos.stream().forEach(r -> {
                ReportInfo reportInfo = reportInfoMapper.selectById(r.getId());
                if (null != reportInfo) {
                    BeanUtils.copyProperties(r, reportInfo);
                    reportInfoMapper.updateById(reportInfo);

//                    ReportInfoVo reportInfoVo = new ReportInfoVo();
//                    BeanUtils.copyProperties(reportInfo, reportInfoVo);
//                    ReportItem reportItem = this.getById(r.getReportId());
//                    if (null != reportItem) {
//                        reportInfoVo.setChartName(reportItem.getChartName());
//                        reportInfoVo.setChartType(reportItem.getChartType());
//                        reportInfoVo.setDataSourceType(reportItem.getDataSourceType());
//                        reportInfoVo.setDataSource(reportItem.getDataSource());
//                        reportInfoVo.setChartSetting(reportItem.getChartSetting());
//                        reportInfoVo.setWorkbench(reportItem.getWorkbench());
//                        reportInfoVo.setThemeColor(reportItem.getThemeColor());
//                        reportInfoVo.setChartElement(reportItem.getChartElement());
//                        reportInfoVo.setStatisValueFormat(reportItem.getStatisValueFormat());
//                        Object object = this.getTypeContent(reportItem.getDataSource(), null, null);
//                        reportInfoVo.setDataObject(object);
//                    }
//                    reportInfoVos.add(reportInfoVo);
                }
            });
        }
        //删除缓存
        redisService.deleteByPrefix(CacheConstants.DATA_BOARD_INFO_KEY+SecurityUtils.getStringUserId()+":*");
        //return reportInfoVos;
    }

    /**
     * 合同数量统计(所有类型的合同数量)
     *
     * @param bo
     * @return
     */
    @Override
    public JSONObject contractAllTypeNums(ItemStatisticsSimpleBo bo) {
        Date startTime = bo.getStartTime();
        Date endTime = bo.getEndTime();
        JSONObject jsonObject = new JSONObject();
        Integer totalNum = 0;
        if (null != startTime && null != endTime) {
            totalNum = conResourceMainMapper.selectCount(new LambdaQueryWrapper<ConResourceMain>().ge(ConResourceMain::getCreateDate, startTime).le(ConResourceMain::getCreateDate, endTime)).intValue();
            totalNum += conResourceMemorandumMapper.selectCount(new LambdaQueryWrapper<ConResourceMemorandum>().ge(ConResourceMemorandum::getCreateDate, startTime).le(ConResourceMemorandum::getCreateDate, endTime)).intValue();
            totalNum += conShippingMapper.selectCount(new LambdaQueryWrapper<ConShipping>().ge(ConShipping::getCreateDate, startTime).le(ConShipping::getCreateDate, endTime)).intValue();
            totalNum += conShippingAgencyMapper.selectCount(new LambdaQueryWrapper<ConShippingAgency>().ge(ConShippingAgency::getCreateDate, startTime).le(ConShippingAgency::getCreateDate, endTime)).intValue();
            totalNum += conBrokerMapper.selectCount(new LambdaQueryWrapper<ConBroker>().ge(ConBroker::getCreateDate, startTime).le(ConBroker::getCreateDate, endTime)).intValue();
            totalNum += conThirdPartyMeasurementMapper.selectCount(new LambdaQueryWrapper<ConThirdPartyMeasurement>().ge(ConThirdPartyMeasurement::getCreateDate, startTime).le(ConThirdPartyMeasurement::getCreateDate, endTime)).intValue();
            totalNum += conInsuranceGoodsMapper.selectCount(new LambdaQueryWrapper<ConInsuranceGoods>().ge(ConInsuranceGoods::getCreateDate, startTime).le(ConInsuranceGoods::getCreateDate, endTime)).intValue();
            totalNum += conInsurancePeopleMapper.selectCount(new LambdaQueryWrapper<ConInsurancePeople>().ge(ConInsurancePeople::getCreateDate, startTime).le(ConInsurancePeople::getCreateDate, endTime)).intValue();
            totalNum += conRefuelingMapper.selectCount(new LambdaQueryWrapper<ConRefueling>().ge(ConRefueling::getCreateDate, startTime).le(ConRefueling::getCreateDate, endTime)).intValue();
            totalNum += conLawyerMapper.selectCount(new LambdaQueryWrapper<ConLawyer>().ge(ConLawyer::getCreateDate, startTime).le(ConLawyer::getCreateDate, endTime)).intValue();
        } else if (null == startTime && null == endTime) {
            totalNum = conResourceMainMapper.selectCount(new QueryWrapper<>()).intValue();
            totalNum += conResourceMemorandumMapper.selectCount(new QueryWrapper<>()).intValue();
            totalNum += conShippingMapper.selectCount(new QueryWrapper<>()).intValue();
            totalNum += conShippingAgencyMapper.selectCount(new QueryWrapper<>()).intValue();
            totalNum += conBrokerMapper.selectCount(new QueryWrapper<>()).intValue();
            totalNum += conThirdPartyMeasurementMapper.selectCount(new QueryWrapper<>()).intValue();
            totalNum += conInsuranceGoodsMapper.selectCount(new QueryWrapper<>()).intValue();
            totalNum += conInsurancePeopleMapper.selectCount(new QueryWrapper<>()).intValue();
            totalNum += conRefuelingMapper.selectCount(new QueryWrapper<>()).intValue();
            totalNum += conLawyerMapper.selectCount(new QueryWrapper<>()).intValue();
        }
        jsonObject.put("totalNum", totalNum);
        return jsonObject;
    }
    /**
     * 统计巴拿马运河通行量数据
     */
    public JSONObject countPanamaCanalTraffic(ItemStatisticsSimpleBo bo){
        List<ShapeUnifyVo> shapeUnifyVos = new ArrayList<>();
        JSONObject jsonObject = new JSONObject();
        String startDate = DateUtil.format(bo.getStartTime(), DatePattern.NORM_DATE_FORMATTER);
        String endDate = DateUtil.format(bo.getEndTime(), DatePattern.NORM_DATE_FORMATTER);
        List<SpBoatsCanalAccess> canalAccesseList = boatsCanalAccessService.queryCanalAccessList("巴拿马运河",startDate,endDate);
        if (CollectionUtil.isNotEmpty(canalAccesseList)){
            canalAccesseList.forEach(item -> {
                ShapeUnifyVo shapeUnifyVo = new ShapeUnifyVo();
                shapeUnifyVo.setKey(item.getDate());
                shapeUnifyVo.setValue(Integer.toString(item.getPassNum()));
                shapeUnifyVo.setTime(Double.toString(item.getAvgPassTime()));
                shapeUnifyVos.add(shapeUnifyVo);
            });
        }
        jsonObject.put("dataList", shapeUnifyVos);
        return jsonObject;
    }

    /**
     * 统计运河通行量数据
     * @param bo
     * @return
     */
    @Override
    public JSONObject statisticsCanalTraffic(ItemStatisticsSimpleBo bo){
        List<ShapeUnifyVo> shapeUnifyVos = new ArrayList<>();
        JSONObject jsonObject = new JSONObject();
        String startDate = DateUtil.format(bo.getStartTime(), DatePattern.NORM_DATE_FORMATTER);
        String endDate = DateUtil.format(bo.getEndTime(), DatePattern.NORM_DATE_FORMATTER);
        List<SpBoatsCanalAccess> canalAccesseList = boatsCanalAccessService.queryCanalAccessList("苏伊士运河",startDate,endDate);
        logger.info("查询运河通行量统计返回结果:{}"+JSONUtil.parse(canalAccesseList));
        if (CollectionUtil.isNotEmpty(canalAccesseList)){
            canalAccesseList.forEach(item -> {
                ShapeUnifyVo shapeUnifyVo = new ShapeUnifyVo();
                shapeUnifyVo.setKey(item.getDate());
                shapeUnifyVo.setValue(Integer.toString(item.getPassNum()));
                shapeUnifyVo.setTime(Double.toString(item.getAvgPassTime()));
                shapeUnifyVos.add(shapeUnifyVo);
            });
        }
        jsonObject.put("dataList", shapeUnifyVos);
        return jsonObject;
    }


    /**
     * 合同类型分布
     *
     * @param bo
     * @return
     */
    @Override
    public JSONObject contractTypeDistribution(ItemStatisticsSimpleBo bo) {
        Date startTime = bo.getStartTime();
        Date endTime = bo.getEndTime();
        JSONObject jsonObject = new JSONObject();
        List<ShapeUnifyVo> shapeUnifyVos = new ArrayList<>();
        ShapeUnifyVo conResourceMainVo = new ShapeUnifyVo();
        ShapeUnifyVo conResourceMemorandumVo = new ShapeUnifyVo();
        ShapeUnifyVo conShippingVo = new ShapeUnifyVo();
        ShapeUnifyVo conShippingAgencyVo = new ShapeUnifyVo();
        ShapeUnifyVo conBrokerVo = new ShapeUnifyVo();
        ShapeUnifyVo conThirdPartyVo = new ShapeUnifyVo();
        ShapeUnifyVo conInsuranceGoodsVo = new ShapeUnifyVo();
        ShapeUnifyVo conInsurancePeopleVo = new ShapeUnifyVo();
        ShapeUnifyVo conRefuelVo = new ShapeUnifyVo();
        ShapeUnifyVo conLawyerVo = new ShapeUnifyVo();

        conResourceMainVo.setKey("资源主合同");
        conResourceMemorandumVo.setKey("资源备忘录合同");
        conShippingVo.setKey("船运合同");
        conShippingAgencyVo.setKey("船舶代理合同");
        conBrokerVo.setKey("船舶经纪人合同");
        conThirdPartyVo.setKey("第三方计量合同");
        conInsuranceGoodsVo.setKey("货险合同");
        conInsurancePeopleVo.setKey("人险合同");
        conRefuelVo.setKey("加油合同");
        conLawyerVo.setKey("律师合同");

        String conResourceMainNum = "0";
        String conResourceMemorandumNum = "0";
        String conShippingNum = "0";
        String conShippingAgencyNum = "0";
        String conBrokerNum = "0";
        String conThirdPartyNum = "0";
        String conInsuranceGoodsNum = "0";
        String conInsurancePeopleNum = "0";
        String conRefuelNum = "0";
        String conLawyerNum = "0";
        if (null != startTime && null != endTime) {
            conResourceMainNum = conResourceMainMapper.selectCount(new LambdaQueryWrapper<ConResourceMain>().ge(ConResourceMain::getCreateDate, startTime).le(ConResourceMain::getCreateDate, endTime)).toString();
            conResourceMemorandumNum = conResourceMemorandumMapper.selectCount(new LambdaQueryWrapper<ConResourceMemorandum>().ge(ConResourceMemorandum::getCreateDate, startTime).le(ConResourceMemorandum::getCreateDate, endTime)).toString();
            conShippingNum = conShippingMapper.selectCount(new LambdaQueryWrapper<ConShipping>().ge(ConShipping::getCreateDate, startTime).le(ConShipping::getCreateDate, endTime)).toString();
            conShippingAgencyNum = conShippingAgencyMapper.selectCount(new LambdaQueryWrapper<ConShippingAgency>().ge(ConShippingAgency::getCreateDate, startTime).le(ConShippingAgency::getCreateDate, endTime)).toString();
            conBrokerNum = conBrokerMapper.selectCount(new LambdaQueryWrapper<ConBroker>().ge(ConBroker::getCreateDate, startTime).le(ConBroker::getCreateDate, endTime)).toString();
            conThirdPartyNum = conThirdPartyMeasurementMapper.selectCount(new LambdaQueryWrapper<ConThirdPartyMeasurement>().ge(ConThirdPartyMeasurement::getCreateDate, startTime).le(ConThirdPartyMeasurement::getCreateDate, endTime)).toString();
            conInsuranceGoodsNum = conInsuranceGoodsMapper.selectCount(new LambdaQueryWrapper<ConInsuranceGoods>().ge(ConInsuranceGoods::getCreateDate, startTime).le(ConInsuranceGoods::getCreateDate, endTime)).toString();
            conInsurancePeopleNum = conInsurancePeopleMapper.selectCount(new LambdaQueryWrapper<ConInsurancePeople>().ge(ConInsurancePeople::getCreateDate, startTime).le(ConInsurancePeople::getCreateDate, endTime)).toString();
            conRefuelNum = conRefuelingMapper.selectCount(new LambdaQueryWrapper<ConRefueling>().ge(ConRefueling::getCreateDate, startTime).le(ConRefueling::getCreateDate, endTime)).toString();
            conLawyerNum = conLawyerMapper.selectCount(new LambdaQueryWrapper<ConLawyer>().ge(ConLawyer::getCreateDate, startTime).le(ConLawyer::getCreateDate, endTime)).toString();
        } else {
            conResourceMainNum = conResourceMainMapper.selectCount(new QueryWrapper<>()).toString();
            conResourceMemorandumNum = conResourceMemorandumMapper.selectCount(new QueryWrapper<>()).toString();
            conShippingNum = conShippingMapper.selectCount(new QueryWrapper<>()).toString();
            conShippingAgencyNum = conShippingAgencyMapper.selectCount(new QueryWrapper<>()).toString();
            conBrokerNum = conBrokerMapper.selectCount(new QueryWrapper<>()).toString();
            conThirdPartyNum = conThirdPartyMeasurementMapper.selectCount(new QueryWrapper<>()).toString();
            conInsuranceGoodsNum = conInsuranceGoodsMapper.selectCount(new QueryWrapper<>()).toString();
            conInsurancePeopleNum = conInsurancePeopleMapper.selectCount(new QueryWrapper<>()).toString();
            conRefuelNum = conRefuelingMapper.selectCount(new QueryWrapper<>()).toString();
            conLawyerNum = conLawyerMapper.selectCount(new QueryWrapper<>()).toString();
        }

        conResourceMainVo.setValue(conResourceMainNum);
        conResourceMemorandumVo.setValue(conResourceMemorandumNum);
        conShippingVo.setValue(conShippingNum);
        conShippingAgencyVo.setValue(conShippingAgencyNum);
        conBrokerVo.setValue(conBrokerNum);
        conThirdPartyVo.setValue(conThirdPartyNum);
        conInsuranceGoodsVo.setValue(conInsuranceGoodsNum);
        conInsurancePeopleVo.setValue(conInsurancePeopleNum);
        conRefuelVo.setValue(conRefuelNum);
        conLawyerVo.setValue(conLawyerNum);

        shapeUnifyVos.add(conResourceMainVo);
        shapeUnifyVos.add(conResourceMemorandumVo);
        shapeUnifyVos.add(conShippingVo);
        shapeUnifyVos.add(conShippingAgencyVo);
        shapeUnifyVos.add(conBrokerVo);
        shapeUnifyVos.add(conThirdPartyVo);
        shapeUnifyVos.add(conInsuranceGoodsVo);
        shapeUnifyVos.add(conInsurancePeopleVo);
        shapeUnifyVos.add(conRefuelVo);
        shapeUnifyVos.add(conLawyerVo);
        jsonObject.put("dataList", shapeUnifyVos);
        return jsonObject;
    }

    /**
     * 资源合同-备忘录统计
     *
     * @param bo
     * @return
     */
    @Override
    public JSONObject conResourceMemorandumTotal(ItemStatisticsSimpleBo bo) {
        Long totalNum = conResourceMemorandumMapper.selectCount(
                new LambdaQueryWrapper<ConResourceMemorandum>()
                        .ge(bo.getStartTime() != null, ConResourceMemorandum::getCreateDate, bo.getStartTime())
                        .le(bo.getEndTime() != null, ConResourceMemorandum::getCreateDate, bo.getEndTime())
        );
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("totalNum", totalNum);
        return jsonObject;
    }

    /**
     * 资源合同-主合同统计
     *
     * @param bo
     * @return
     */
    @Override
    public JSONObject conResourceMainTotal(ItemStatisticsSimpleBo bo) {
        Date startTime = bo.getStartTime();
        Date endTime = bo.getEndTime();
        JSONObject jsonObject = new JSONObject();
        Integer totalNum = 0;
        if (null != startTime && null != endTime) {
            totalNum += conResourceMainMapper.selectCount(new LambdaQueryWrapper<ConResourceMain>().ge(ConResourceMain::getCreateDate, startTime).le(ConResourceMain::getCreateDate, endTime)).intValue();
        } else if (null == startTime && null == endTime) {
            totalNum += conResourceMainMapper.selectCount(new QueryWrapper<>()).intValue();
        }
        jsonObject.put("totalNum", totalNum);
        return jsonObject;
    }

    /**
     * 备忘录贸易类型分布
     *
     * @param bo
     * @return
     */
    @Override
    public JSONObject conResourceMemorandumTradeType(ItemStatisticsSimpleBo bo) {
        Date startTime = bo.getStartTime();
        Date endTime = bo.getEndTime();
        JSONObject jsonObject = new JSONObject();
        List<ShapeUnifyVo> shapeUnifyVos = new ArrayList<>();
        List<SysConstant> constants = constantMapper.selectList(new LambdaQueryWrapper<SysConstant>().eq(SysConstant::getType, "贸易类型"));
        if (null != constants && constants.size() > 0) {
            constants.stream().forEach(c -> {
                ShapeUnifyVo shapeUnifyVo = new ShapeUnifyVo();
                shapeUnifyVo.setKey(c.getConstLabel());

                Integer num = 0;
                if (null != startTime && null != endTime) {
                    num = conResourceMemorandumMapper.selectCount(new LambdaQueryWrapper<ConResourceMemorandum>()
                            .ge(ConResourceMemorandum::getCreateDate, startTime)
                            .le(ConResourceMemorandum::getCreateDate, endTime)
                            .eq(ConResourceMemorandum::getTradeType, c.getConstValue())).intValue();
                } else if (null == startTime && null == endTime) {
                    num = conResourceMemorandumMapper.selectCount(new LambdaQueryWrapper<ConResourceMemorandum>()
                            .eq(ConResourceMemorandum::getTradeType, c.getConstValue())).intValue();
                }
                shapeUnifyVo.setValue(num.toString());
                shapeUnifyVos.add(shapeUnifyVo);
            });
        }
        jsonObject.put("dataList", shapeUnifyVos);
        return jsonObject;
    }

    /**
     * 备忘录类贸易模式分布
     *
     * @param bo
     * @return
     */
    @Override
    public JSONObject conResourceMemorandumTradeModel(ItemStatisticsSimpleBo bo) {
        Date startTime = bo.getStartTime();
        Date endTime = bo.getEndTime();
        JSONObject jsonObject = new JSONObject();
        List<ShapeUnifyVo> shapeUnifyVos = new ArrayList<>();
        List<SysConstant> constants = constantMapper.selectList(new LambdaQueryWrapper<SysConstant>().eq(SysConstant::getType, "贸易模式"));
        if (null != constants && constants.size() > 0) {
            constants.stream().forEach(c -> {
                ShapeUnifyVo shapeUnifyVo = new ShapeUnifyVo();
                shapeUnifyVo.setKey(c.getConstLabel());

                Integer num = 0;
                if (null != startTime && null != endTime) {
                    num = conResourceMemorandumMapper.selectCount(new LambdaQueryWrapper<ConResourceMemorandum>()
                            .ge(ConResourceMemorandum::getCreateDate, startTime)
                            .le(ConResourceMemorandum::getCreateDate, endTime)
                            .eq(ConResourceMemorandum::getTradeModel, c.getConstValue())).intValue();
                } else if (null == startTime && null == endTime) {
                    num = conResourceMemorandumMapper.selectCount(new LambdaQueryWrapper<ConResourceMemorandum>()
                            .eq(ConResourceMemorandum::getTradeModel, c.getConstValue())).intValue();
                }
                shapeUnifyVo.setValue(num.toString());
                shapeUnifyVos.add(shapeUnifyVo);
            });
        }
        jsonObject.put("dataList", shapeUnifyVos);
        return jsonObject;
    }

    /**
     * 备忘录类贸易主体分布
     *
     * @param bo
     * @return
     */
    @Override
    public JSONObject conResourceMemorandumTradeBody(ItemStatisticsSimpleBo bo) {
        Date startTime = bo.getStartTime();
        Date endTime = bo.getEndTime();
        JSONObject jsonObject = new JSONObject();
        List<ShapeUnifyVo> shapeUnifyVos = new ArrayList<>();
        List<SysConstant> constants = constantMapper.selectList(new LambdaQueryWrapper<SysConstant>().eq(SysConstant::getType, "贸易主体"));
        if (null != constants && constants.size() > 0) {
            constants.stream().forEach(c -> {
                ShapeUnifyVo shapeUnifyVo = new ShapeUnifyVo();
                shapeUnifyVo.setKey(c.getConstLabel());

                Integer num = 0;
                if (null != startTime && null != endTime) {
                    num = conResourceMemorandumMapper.selectCount(new LambdaQueryWrapper<ConResourceMemorandum>()
                            .ge(ConResourceMemorandum::getCreateDate, startTime)
                            .le(ConResourceMemorandum::getCreateDate, endTime)
                            .eq(ConResourceMemorandum::getTradeBody, c.getConstValue())).intValue();
                } else if (null == startTime && null == endTime) {
                    num = conResourceMemorandumMapper.selectCount(new LambdaQueryWrapper<ConResourceMemorandum>()
                            .eq(ConResourceMemorandum::getTradeBody, c.getConstValue())).intValue();
                }
                shapeUnifyVo.setValue(num.toString());
                shapeUnifyVos.add(shapeUnifyVo);
            });
        }
        jsonObject.put("dataList", shapeUnifyVos);
        return jsonObject;
    }

    /**
     * 备忘录交付方式分布
     *
     * @param bo
     * @return
     */
    @Override
    public JSONObject conResourceMemorandumDeliveryType(ItemStatisticsSimpleBo bo) {
        Date startTime = bo.getStartTime();
        Date endTime = bo.getEndTime();
        JSONObject jsonObject = new JSONObject();
        List<ShapeUnifyVo> shapeUnifyVos = new ArrayList<>();
        List<SysConstant> constants = constantMapper.selectList(new LambdaQueryWrapper<SysConstant>().eq(SysConstant::getType, "交货方式"));
        if (null != constants && constants.size() > 0) {
            constants.stream().forEach(c -> {
                ShapeUnifyVo shapeUnifyVo = new ShapeUnifyVo();
                shapeUnifyVo.setKey(c.getConstLabel());

                Integer num = 0;
                if (null != startTime && null != endTime) {
                    num = conResourceMemorandumMapper.selectCount(new LambdaQueryWrapper<ConResourceMemorandum>()
                            .ge(ConResourceMemorandum::getCreateDate, startTime)
                            .le(ConResourceMemorandum::getCreateDate, endTime)
                            .eq(ConResourceMemorandum::getDeliveryType, c.getConstValue())).intValue();
                } else if (null == startTime && null == endTime) {
                    num = conResourceMemorandumMapper.selectCount(new LambdaQueryWrapper<ConResourceMemorandum>()
                            .eq(ConResourceMemorandum::getDeliveryType, c.getConstValue())).intValue();
                }
                shapeUnifyVo.setValue(num.toString());
                shapeUnifyVos.add(shapeUnifyVo);
            });
        }
        jsonObject.put("dataList", shapeUnifyVos);
        return jsonObject;
    }

    /**
     * 备忘录状态分布
     *
     * @param bo
     * @return
     */
    @Override
    public JSONObject conResourceMemorandumStatus(ItemStatisticsSimpleBo bo) {
        Date startTime = bo.getStartTime();
        Date endTime = bo.getEndTime();
        JSONObject jsonObject = new JSONObject();
        List<ShapeUnifyVo> shapeUnifyVos = new ArrayList<>();
        List<SysConstant> constants = constantMapper.selectList(new LambdaQueryWrapper<SysConstant>().eq(SysConstant::getType, "合同状态"));
        if (null != constants && constants.size() > 0) {
            constants.stream().forEach(c -> {
                ShapeUnifyVo shapeUnifyVo = new ShapeUnifyVo();
                shapeUnifyVo.setKey(c.getConstLabel());

                Integer num = 0;
                if (null != startTime && null != endTime) {
                    num = conResourceMemorandumMapper.selectCount(new LambdaQueryWrapper<ConResourceMemorandum>()
                            .ge(ConResourceMemorandum::getCreateDate, startTime)
                            .le(ConResourceMemorandum::getCreateDate, endTime)
                            .eq(ConResourceMemorandum::getStatus, c.getConstValue())).intValue();
                } else if (null == startTime && null == endTime) {
                    num = conResourceMemorandumMapper.selectCount(new LambdaQueryWrapper<ConResourceMemorandum>()
                            .eq(ConResourceMemorandum::getStatus, c.getConstValue())).intValue();
                }
                shapeUnifyVo.setValue(num.toString());
                shapeUnifyVos.add(shapeUnifyVo);
            });
        }
        jsonObject.put("dataList", shapeUnifyVos);
        return jsonObject;
    }

    /**
     * 主合同贸易主体分布
     *
     * @param bo
     * @return
     */
    @Override
    public JSONObject conResourceMainTradeBody(ItemStatisticsSimpleBo bo) {
        Date startTime = bo.getStartTime();
        Date endTime = bo.getEndTime();
        JSONObject jsonObject = new JSONObject();
        List<ShapeUnifyVo> shapeUnifyVos = new ArrayList<>();
        List<SysConstant> constants = constantMapper.selectList(new LambdaQueryWrapper<SysConstant>().eq(SysConstant::getType, "贸易主体"));
        if (null != constants && constants.size() > 0) {
            constants.stream().forEach(c -> {
                ShapeUnifyVo shapeUnifyVo = new ShapeUnifyVo();
                shapeUnifyVo.setKey(c.getConstLabel());

                Integer num = 0;
                if (null != startTime && null != endTime) {
                    num = conResourceMainMapper.selectCount(new LambdaQueryWrapper<ConResourceMain>()
                            .ge(ConResourceMain::getCreateDate, startTime)
                            .le(ConResourceMain::getCreateDate, endTime)
                            .eq(ConResourceMain::getTradeBody, c.getConstValue())).intValue();
                } else if (null == startTime && null == endTime) {
                    num = conResourceMainMapper.selectCount(new LambdaQueryWrapper<ConResourceMain>()
                            .eq(ConResourceMain::getTradeBody, c.getConstValue())).intValue();
                }
                shapeUnifyVo.setValue(num.toString());
                shapeUnifyVos.add(shapeUnifyVo);
            });
        }
        jsonObject.put("dataList", shapeUnifyVos);
        return jsonObject;
    }

    /**
     * 船运合同统计
     *
     * @param bo
     * @return
     */
    @Override
    public JSONObject conShippingTotal(ItemStatisticsSimpleBo bo) {
        Date startTime = bo.getStartTime();
        Date endTime = bo.getEndTime();
        JSONObject jsonObject = new JSONObject();
        Integer totalNum = 0;
        if (null != startTime && null != endTime) {
            totalNum += conShippingMapper.selectCount(new LambdaQueryWrapper<ConShipping>()
                    .ge(ConShipping::getCreateDate, startTime)
                    .le(ConShipping::getCreateDate, endTime)).intValue();
        } else if (null == startTime && null == endTime) {
            totalNum += conShippingMapper.selectCount(new QueryWrapper<>()).intValue();
        }
        jsonObject.put("totalNum", totalNum);
        return jsonObject;
    }

    /**
     * 船运合同类型分布
     *
     * @param bo
     * @return
     */
    @Override
    public JSONObject conShippingContractType(ItemStatisticsSimpleBo bo) {
        Date startTime = bo.getStartTime();
        Date endTime = bo.getEndTime();
        JSONObject jsonObject = new JSONObject();
        List<ShapeUnifyVo> shapeUnifyVos = new ArrayList<>();
        List<SysConstant> constants = constantMapper.selectList(new LambdaQueryWrapper<SysConstant>().eq(SysConstant::getType, "船运合同类型"));
        if (null != constants && constants.size() > 0) {
            constants.stream().forEach(c -> {
                ShapeUnifyVo shapeUnifyVo = new ShapeUnifyVo();
                shapeUnifyVo.setKey(c.getConstLabel());

                Integer num = 0;
                if (null != startTime && null != endTime) {
                    num = conShippingMapper.selectCount(new LambdaQueryWrapper<ConShipping>()
                            .ge(ConShipping::getCreateDate, startTime)
                            .le(ConShipping::getCreateDate, endTime)
                            .eq(ConShipping::getContractType, c.getConstValue())).intValue();
                } else if (null == startTime && null == endTime) {
                    num = conShippingMapper.selectCount(new LambdaQueryWrapper<ConShipping>()
                            .eq(ConShipping::getContractType, c.getConstValue())).intValue();
                }
                shapeUnifyVo.setValue(num.toString());
                shapeUnifyVos.add(shapeUnifyVo);
            });
        }
        jsonObject.put("dataList", shapeUnifyVos);
        return jsonObject;
    }

    /**
     * 不同类型备忘录状态分布
     *
     * @param bo
     * @return
     */
    @Override
    public JSONObject memorandumTypeStatus(ItemStatisticsSimpleBo bo) {
        Date startTime = bo.getStartTime();
        Date endTime = bo.getEndTime();
        JSONObject jsonObject = new JSONObject();
        List<StackedDiagramVo> stackedDiagramVos = new ArrayList<>();
        List<SysConstant> constants = constantMapper.selectList(new LambdaQueryWrapper<SysConstant>().eq(SysConstant::getType, "贸易类型"));
        if (null != constants && constants.size() > 0) {
            constants.stream().forEach(c -> {
                StackedDiagramVo stackedDiagramVo = new StackedDiagramVo();
                stackedDiagramVo.setName(c.getConstLabel());
                List<SysConstant> constantsNew = constantMapper.selectList(new LambdaQueryWrapper<SysConstant>().eq(SysConstant::getType, "合同状态"));
                if (null != constantsNew && constantsNew.size() > 0) {
                    constantsNew.stream().forEach(s -> {
                        StackedDiagramItemVo stackedDiagramItemVo = new StackedDiagramItemVo();
                        stackedDiagramItemVo.setKey(s.getConstLabel());
                        Integer num = 0;
                        if (null != startTime && null != endTime) {
                            num = conResourceMemorandumMapper.selectCount(new LambdaQueryWrapper<ConResourceMemorandum>()
                                    .ge(ConResourceMemorandum::getCreateDate, startTime)
                                    .le(ConResourceMemorandum::getCreateDate, endTime)
                                    .eq(ConResourceMemorandum::getStatus, s.getConstValue())
                                    .eq(ConResourceMemorandum::getTradeType, c.getConstValue())).intValue();
                        } else if (null == startTime && null == endTime) {
                            num = conResourceMemorandumMapper.selectCount(new LambdaQueryWrapper<ConResourceMemorandum>()
                                    .eq(ConResourceMemorandum::getTradeType, c.getConstValue())
                                    .eq(ConResourceMemorandum::getStatus, s.getConstValue())).intValue();
                        }
                        stackedDiagramItemVo.setValue(num.toString());
                        stackedDiagramVo.getList().add(stackedDiagramItemVo);
                    });
                }
                stackedDiagramVos.add(stackedDiagramVo);
            });
        }
        jsonObject.put("dataList", stackedDiagramVos);
        return jsonObject;
    }

    /**
     * 船运合同贸易主体分布
     *
     * @param bo
     * @return
     */
    @Override
    public JSONObject conShippingTradeBody(ItemStatisticsSimpleBo bo) {
        Date startTime = bo.getStartTime();
        Date endTime = bo.getEndTime();
        JSONObject jsonObject = new JSONObject();
        List<ShapeUnifyVo> shapeUnifyVos = new ArrayList<>();
        List<SysConstant> constants = constantMapper.selectList(new LambdaQueryWrapper<SysConstant>().eq(SysConstant::getType, "贸易主体"));
        if (null != constants && constants.size() > 0) {
            constants.stream().forEach(c -> {
                ShapeUnifyVo shapeUnifyVo = new ShapeUnifyVo();
                shapeUnifyVo.setKey(c.getConstLabel());

                Integer num = 0;
                if (null != startTime && null != endTime) {
                    num = conShippingMapper.selectCount(new LambdaQueryWrapper<ConShipping>()
                            .ge(ConShipping::getCreateDate, startTime)
                            .le(ConShipping::getCreateDate, endTime)
                            .eq(ConShipping::getTradeBody, c.getConstValue())).intValue();
                } else if (null == startTime && null == endTime) {
                    num = conShippingMapper.selectCount(new LambdaQueryWrapper<ConShipping>()
                            .eq(ConShipping::getTradeBody, c.getConstValue())).intValue();
                }
                shapeUnifyVo.setValue(num.toString());
                shapeUnifyVos.add(shapeUnifyVo);
            });
        }
        jsonObject.put("dataList", shapeUnifyVos);
        return jsonObject;
    }

    /**
     * 船舶租入贸易主体分布
     *
     * @param bo
     * @return
     */
    @Override
    public JSONObject conShippingRentTradeBody(ItemStatisticsSimpleBo bo) {
        Date startTime = bo.getStartTime();
        Date endTime = bo.getEndTime();
        JSONObject jsonObject = new JSONObject();
        List<ShapeUnifyVo> shapeUnifyVos = new ArrayList<>();
        List<SysConstant> constants = constantMapper.selectList(new LambdaQueryWrapper<SysConstant>().eq(SysConstant::getType, "贸易主体"));
        if (null != constants && constants.size() > 0) {
            constants.stream().forEach(c -> {
                ShapeUnifyVo shapeUnifyVo = new ShapeUnifyVo();
                shapeUnifyVo.setKey(c.getConstLabel());

                List<Integer> contractTypes = new ArrayList<>();
                contractTypes.add(1);
                contractTypes.add(2);
                Integer num = 0;
                if (null != startTime && null != endTime) {
                    num = conShippingMapper.selectCount(new LambdaQueryWrapper<ConShipping>()
                            .ge(ConShipping::getCreateDate, startTime)
                            .le(ConShipping::getCreateDate, endTime)
                            .eq(ConShipping::getTradeBody, c.getConstValue())
                            .in(ConShipping::getContractType,contractTypes)).intValue();
                } else if (null == startTime && null == endTime) {
                    num = conShippingMapper.selectCount(new LambdaQueryWrapper<ConShipping>()
                            .eq(ConShipping::getTradeBody, c.getConstValue())
                            .in(ConShipping::getContractType,contractTypes)
                            ).intValue();
                }
                shapeUnifyVo.setValue(num.toString());
                shapeUnifyVos.add(shapeUnifyVo);
            });
        }
        jsonObject.put("dataList", shapeUnifyVos);
        return jsonObject;
    }

    /**
     * 船运合同类型及贸易主体分布
     *
     * @param bo
     * @return
     */
    @Override
    public JSONObject conShippingContractTypeAndTradeBody(ItemStatisticsSimpleBo bo) {
        Date startTime = bo.getStartTime();
        Date endTime = bo.getEndTime();
        JSONObject jsonObject = new JSONObject();
        List<StackedDiagramVo> stackedDiagramVos = new ArrayList<>();
        List<SysConstant> constants = constantMapper.selectList(new LambdaQueryWrapper<SysConstant>().eq(SysConstant::getType, "船运合同类型"));
        if (null != constants && constants.size() > 0) {
            constants.stream().forEach(c -> {
                StackedDiagramVo stackedDiagramVo = new StackedDiagramVo();
                stackedDiagramVo.setName(c.getConstLabel());
                List<SysConstant> constantsNew = constantMapper.selectList(new LambdaQueryWrapper<SysConstant>().eq(SysConstant::getType, "贸易主体"));
                if (null != constantsNew && constantsNew.size() > 0) {
                    constantsNew.stream().forEach(s -> {
                        StackedDiagramItemVo stackedDiagramItemVo = new StackedDiagramItemVo();
                        stackedDiagramItemVo.setKey(s.getConstLabel());
                        Integer num = 0;
                        if (null != startTime && null != endTime) {
                            num = conShippingMapper.selectCount(new LambdaQueryWrapper<ConShipping>()
                                    .ge(ConShipping::getCreateDate, startTime)
                                    .le(ConShipping::getCreateDate, endTime)
                                    .eq(ConShipping::getTradeBody, s.getConstValue())
                                    .eq(ConShipping::getContractType,c.getConstValue())).intValue();
                        } else if (null == startTime && null == endTime) {
                            num = conShippingMapper.selectCount(new LambdaQueryWrapper<ConShipping>()
                                    .eq(ConShipping::getTradeBody, s.getConstValue())
                                    .eq(ConShipping::getContractType,c.getConstValue())).intValue();
                        }
                        stackedDiagramItemVo.setValue(num.toString());
                        stackedDiagramVo.getList().add(stackedDiagramItemVo);
                    });
                }
                stackedDiagramVos.add(stackedDiagramVo);
            });
        }
        jsonObject.put("dataList", stackedDiagramVos);
        return jsonObject;
    }

    /**
     * 船运合同类型及状态分布
     *
     * @param bo
     * @return
     */
    @Override
    public JSONObject conShippingContractTypeAndStatus(ItemStatisticsSimpleBo bo) {
        Date startTime = bo.getStartTime();
        Date endTime = bo.getEndTime();
        JSONObject jsonObject = new JSONObject();
        List<StackedDiagramVo> stackedDiagramVos = new ArrayList<>();
        List<SysConstant> constants = constantMapper.selectList(new LambdaQueryWrapper<SysConstant>().eq(SysConstant::getType, "船运合同类型"));
        if (null != constants && constants.size() > 0) {
            constants.stream().forEach(c -> {
                StackedDiagramVo stackedDiagramVo = new StackedDiagramVo();
                stackedDiagramVo.setName(c.getConstLabel());
                List<SysConstant> constantsNew = constantMapper.selectList(new LambdaQueryWrapper<SysConstant>().eq(SysConstant::getType, "船运合同状态"));
                if (null != constantsNew && constantsNew.size() > 0) {
                    constantsNew.stream().forEach(s -> {
                        StackedDiagramItemVo stackedDiagramItemVo = new StackedDiagramItemVo();
                        stackedDiagramItemVo.setKey(s.getConstLabel());
                        Integer num = 0;
                        if (null != startTime && null != endTime) {
                            num = conShippingMapper.selectCount(new LambdaQueryWrapper<ConShipping>()
                                    .ge(ConShipping::getCreateDate, startTime)
                                    .le(ConShipping::getCreateDate, endTime)
                                    .eq(ConShipping::getStatus, s.getConstValue())
                                    .eq(ConShipping::getContractType,c.getConstValue())).intValue();
                        } else if (null == startTime && null == endTime) {
                            num = conShippingMapper.selectCount(new LambdaQueryWrapper<ConShipping>()
                                    .eq(ConShipping::getStatus, s.getConstValue())
                                    .eq(ConShipping::getContractType,c.getConstValue())).intValue();
                        }
                        stackedDiagramItemVo.setValue(num.toString());
                        stackedDiagramVo.getList().add(stackedDiagramItemVo);
                    });
                }
                stackedDiagramVos.add(stackedDiagramVo);
            });
        }
        jsonObject.put("dataList", stackedDiagramVos);
        return jsonObject;
    }

    /**
     * LNG船舶状态分布
     *
     * @param bo
     * @return
     */
    @Override
    public JSONObject lngShipStatus(ItemStatisticsSimpleBo bo) {
        Date startTime = bo.getStartTime();
        Date endTime = bo.getEndTime();
        JSONObject jsonObject = new JSONObject();
        List<ShapeUnifyVo> shapeUnifyVos = new ArrayList<>();
        Map<String, List<IhsShipBase>> ihsShipBaseMap = new HashMap<>();

        if (null != startTime && null != endTime) {
            ihsShipBaseMap = ihsShipBaseService.queryShipBase(startTime,endTime).stream().collect(Collectors.groupingBy(IhsShipBase::getShipStatus));
//            ihsShipBaseMap = ihsShipBaseMapper.queryShipBase(new LambdaQueryWrapper<IhsShipBase>()
//                            .ge(IhsShipBase::getUpdateTime, startTime)
//                            .le(IhsShipBase::getUpdateTime, endTime))
//                    .stream().collect(Collectors.groupingBy(IhsShipBase::getShipStatus));
        } else if (null == startTime && null == endTime) {
            ihsShipBaseMap = ihsShipBaseService.queryShipBaseList().stream().collect(Collectors.groupingBy(IhsShipBase :: getShipStatus));
//            ihsShipBaseMap = ihsShipBaseMapper.selectList(new LambdaQueryWrapper<>()).stream().collect(Collectors.groupingBy(IhsShipBase::getShipStatus));
        }

        for (String shipStatusName : ihsShipBaseMap.keySet()) {
            ShapeUnifyVo shapeUnifyVo = new ShapeUnifyVo();
            shapeUnifyVo.setKey(shipStatusName);
            Integer num = ihsShipBaseMap.get(shipStatusName).size();
            shapeUnifyVo.setValue(num.toString());
            shapeUnifyVos.add(shapeUnifyVo);
        }
        jsonObject.put("dataList", shapeUnifyVos);
        return jsonObject;
    }

    /**
     * LNG船舶船型分布
     *
     * @param bo
     * @return
     */
    @Override
    public JSONObject lngShipTypeGroup(ItemStatisticsSimpleBo bo) {
        Date startTime = bo.getStartTime();
        Date endTime = bo.getEndTime();
        JSONObject jsonObject = new JSONObject();
        List<ShapeUnifyVo> shapeUnifyVos = new ArrayList<>();
//        Map<String, List<IhsShipBase>> ihsShipBaseMap = new HashMap<>();
//
//        if (null != startTime && null != endTime) {
//            ihsShipBaseMap = ihsShipBaseService.queryShipBase(startTime,endTime).stream().collect(Collectors.groupingBy(IhsShipBase::getShipTypeGroup));
////            ihsShipBaseMap = ihsShipBaseMapper.selectList(new LambdaQueryWrapper<IhsShipBase>()
////                            .ge(IhsShipBase::getCreateDate, startTime)
////                            .le(IhsShipBase::getCreateDate, endTime))
////                    .stream().collect(Collectors.groupingBy(IhsShipBase::getShipTypeGroup));
//        } else if (null == startTime && null == endTime) {
//            ihsShipBaseMap = ihsShipBaseService.queryShipBaseList().stream().collect(Collectors.groupingBy(IhsShipBase::getShipTypeGroup));
////            ihsShipBaseMap = ihsShipBaseMapper.selectList(new LambdaQueryWrapper<>()).stream().collect(Collectors.groupingBy(IhsShipBase::getShipTypeGroup));
//        }

//        for (String shipTypeGroupName : ihsShipBaseMap.keySet()) {
//            ShapeUnifyVo shapeUnifyVo = new ShapeUnifyVo();
//            shapeUnifyVo.setKey(shipTypeGroupName);
//            Integer num = ihsShipBaseMap.get(shipTypeGroupName).size();
//            shapeUnifyVo.setValue(num.toString());
//            shapeUnifyVos.add(shapeUnifyVo);
//        }

        List<IhsShipBase> ihsShipBaseMap = new ArrayList<>();

        if (null != startTime && null != endTime) {
            ihsShipBaseMap = ihsShipBaseService.queryShipType(startTime,endTime);
        } else if (null == startTime && null == endTime) {
            ihsShipBaseMap = ihsShipBaseService.queryShipTypeList();
        }

        Map<String, Integer> countMap = new HashMap<>();
        countMap.put("LNG-Small Gas Carrier", 0);
        countMap.put("LNG-Conventional Gas Carrier", 0);
        countMap.put("LNG-Q Flex", 0);
        countMap.put("LNG-Q Max", 0);

        for (IhsShipBase shipBase : ihsShipBaseMap) {
            Integer gasCapacity = shipBase.getGasCapacity();

            if (gasCapacity < 120000) {
                countMap.put("LNG-Small Gas Carrier", countMap.get("LNG-Small Gas Carrier") + 1);
            } else if (gasCapacity >= 120001 && gasCapacity <= 200000) {
                countMap.put("LNG-Conventional Gas Carrier", countMap.get("LNG-Conventional Gas Carrier") + 1);
            } else if (gasCapacity >= 200001 && gasCapacity <= 220000) {
                countMap.put("LNG-Q Flex", countMap.get("LNG-Q Flex") + 1);
            } else if (gasCapacity >= 220001) {
                countMap.put("LNG-Q Max", countMap.get("LNG-Q Max") + 1);
            }
        }
        for (Map.Entry<String, Integer> entry : countMap.entrySet()) {
            ShapeUnifyVo vo = new ShapeUnifyVo();
            vo.setKey(entry.getKey());
            vo.setValue(String.valueOf(entry.getValue()));
            shapeUnifyVos.add(vo);
        }

        jsonObject.put("dataList", shapeUnifyVos);
        return jsonObject;
    }

    /**
     * LNG船舶船龄分布
     *
     * @param bo
     * @return
     */
    @Override
    public JSONObject lngShipYearOfBuild(ItemStatisticsSimpleBo bo) {
        Date startTime = bo.getStartTime();
        Date endTime = bo.getEndTime();
        JSONObject jsonObject = new JSONObject();
        List<ShapeUnifyVo> shapeUnifyVos = new ArrayList<>();
        ShapeUnifyVo shapeUnifyFiveVo = new ShapeUnifyVo();
        ShapeUnifyVo shapeUnifyTenVo = new ShapeUnifyVo();
        ShapeUnifyVo shapeUnifyFifteenVo = new ShapeUnifyVo();
        ShapeUnifyVo shapeUnifyTwentyVo = new ShapeUnifyVo();
        ShapeUnifyVo shapeUnifyOverTwentyVo = new ShapeUnifyVo();
        shapeUnifyFiveVo.setKey("<5年");
        shapeUnifyTenVo.setKey("5-10年");
        shapeUnifyFifteenVo.setKey("10-15年");
        shapeUnifyTwentyVo.setKey("15-20年");
        shapeUnifyOverTwentyVo.setKey("20年以上");

        Integer fiveNum = 0;
        Integer tenNum = 0;
        Integer fifteenNum = 0;
        Integer twentyNum = 0;
        Integer overTwentyNum = 0;
        Calendar cal = Calendar.getInstance();  // 获取当前时间的Calendar实例
        Integer year = cal.get(Calendar.YEAR);
        if (null != startTime && null != endTime) {
            List<IhsShipBase> shipBaseList = ihsShipBaseService.queryShipBase(startTime, endTime);
            fiveNum = shipBaseList.stream().filter(n->(year-n.getYearOfBuild())<5).collect(Collectors.toList()).size();
            tenNum = shipBaseList.stream().filter(n->(year-n.getYearOfBuild()) >= 5 && (year-n.getYearOfBuild()) < 10).collect(Collectors.toList()).size();
            fifteenNum = shipBaseList.stream().filter(n->(year-n.getYearOfBuild()) >= 10 && (year-n.getYearOfBuild()) < 15).collect(Collectors.toList()).size();
            twentyNum = shipBaseList.stream().filter(n->(year-n.getYearOfBuild()) >= 15 && (year-n.getYearOfBuild()) < 20).collect(Collectors.toList()).size();
            overTwentyNum = shipBaseList.stream().filter(n->(year-n.getYearOfBuild()) >= 20).collect(Collectors.toList()).size();
        } else if (null == startTime && null == endTime) {
            List<IhsShipBase> shipBaseList = ihsShipBaseService.queryShipBaseList();
            fiveNum = shipBaseList.stream().filter(n->(year-n.getYearOfBuild())<5).collect(Collectors.toList()).size();
            tenNum = shipBaseList.stream().filter(n->(year-n.getYearOfBuild()) >= 5 && (year-n.getYearOfBuild()) < 10).collect(Collectors.toList()).size();
            fifteenNum = shipBaseList.stream().filter(n->(year-n.getYearOfBuild()) >= 10 && (year-n.getYearOfBuild()) < 15).collect(Collectors.toList()).size();
            twentyNum = shipBaseList.stream().filter(n->(year-n.getYearOfBuild()) >= 15 && (year-n.getYearOfBuild()) < 20).collect(Collectors.toList()).size();
            overTwentyNum = shipBaseList.stream().filter(n->(year-n.getYearOfBuild()) >= 20).collect(Collectors.toList()).size();
        }
        shapeUnifyFiveVo.setValue(fiveNum.toString());
        shapeUnifyTenVo.setValue(tenNum.toString());
        shapeUnifyFifteenVo.setValue(fifteenNum.toString());
        shapeUnifyTwentyVo.setValue(twentyNum.toString());
        shapeUnifyOverTwentyVo.setValue(overTwentyNum.toString());

        shapeUnifyVos.add(shapeUnifyFiveVo);
        shapeUnifyVos.add(shapeUnifyTenVo);
        shapeUnifyVos.add(shapeUnifyFifteenVo);
        shapeUnifyVos.add(shapeUnifyTwentyVo);
        shapeUnifyVos.add(shapeUnifyOverTwentyVo);

        jsonObject.put("dataList", shapeUnifyVos);
        return jsonObject;
    }

    /**
     * LNG船舶主机类型分布
     *
     * @param bo
     * @return
     */
    @Override
    public JSONObject lngShipMainEngineType(ItemStatisticsSimpleBo bo) {
        Date startTime = bo.getStartTime();
        Date endTime = bo.getEndTime();
        JSONObject jsonObject = new JSONObject();
        List<ShapeUnifyVo> shapeUnifyVos = new ArrayList<>();

        Map<String, List<IshShipBaseExtend>> ihsShipBaseMap = new HashMap<>();

        if (null != startTime && null != endTime) {
//            ihsShipBaseMap = ihsShipBaseService.queryShipBase(startTime,endTime).stream().collect(Collectors.groupingBy(IhsShipBase::getMainEngineType));
            ihsShipBaseMap = ihsShipBaseService.selectInMysql(startTime,endTime).stream().collect(Collectors.groupingBy(IshShipBaseExtend::getEngineType));
//            ihsShipBaseMap = ihsShipBaseMapper.selectList(new LambdaQueryWrapper<IhsShipBase>()
//                            .ge(IhsShipBase::getCreateDate, startTime)
//                            .le(IhsShipBase::getCreateDate, endTime))
//                    .stream().collect(Collectors.groupingBy(IhsShipBase::getMainEngineType));
        } else if (null == startTime && null == endTime) {
//            ihsShipBaseMap = ihsShipBaseService.queryShipBaseList().stream().collect(Collectors.groupingBy(IhsShipBase::getMainEngineType));
            ihsShipBaseMap = ihsShipBaseService.selectInMysqlList().stream().collect(Collectors.groupingBy(IshShipBaseExtend::getEngineType));
//            ihsShipBaseMap = ihsShipBaseMapper.selectList(new LambdaQueryWrapper<>()).stream().collect(Collectors.groupingBy(IhsShipBase::getMainEngineType));
        }

        for (String shipMainEngineTypeName : ihsShipBaseMap.keySet()) {
            ShapeUnifyVo shapeUnifyVo = new ShapeUnifyVo();
            shapeUnifyVo.setKey(shipMainEngineTypeName);
            Integer num = ihsShipBaseMap.get(shipMainEngineTypeName).size();
            shapeUnifyVo.setValue(num.toString());
            shapeUnifyVos.add(shapeUnifyVo);
        }

        jsonObject.put("dataList", shapeUnifyVos);
        return jsonObject;
    }

    /**
     * LNG船舶建造船厂分布
     *
     * @param bo
     * @return
     */
    @Override
    public JSONObject lngShipbuilder(ItemStatisticsSimpleBo bo) {
        Date startTime = bo.getStartTime();
        Date endTime = bo.getEndTime();
        JSONObject jsonObject = new JSONObject();
        List<ShapeUnifyVo> shapeUnifyVos = new ArrayList<>();

        Map<String, List<IhsShipBase>> ihsShipBaseMap = new HashMap<>();

        if (null != startTime && null != endTime) {
            ihsShipBaseMap = ihsShipBaseService.queryShipBase(startTime,endTime).stream().collect(Collectors.groupingBy(IhsShipBase::getShipBuilder));
//            ihsShipBaseMap = ihsShipBaseMapper.selectList(new LambdaQueryWrapper<IhsShipBase>()
//                            .ge(IhsShipBase::getCreateDate, startTime)
//                            .le(IhsShipBase::getCreateDate, endTime))
//                    .stream().collect(Collectors.groupingBy(IhsShipBase::getShipBuilder));
        } else if (null == startTime && null == endTime) {
            ihsShipBaseMap = ihsShipBaseService.queryShipBaseList().stream().collect(Collectors.groupingBy(IhsShipBase::getShipBuilder));

//            ihsShipBaseMap = ihsShipBaseMapper.selectList(new LambdaQueryWrapper<>()).stream().collect(Collectors.groupingBy(IhsShipBase::getShipBuilder));
        }

        for (String shipBuilderName : ihsShipBaseMap.keySet()) {
            ShapeUnifyVo shapeUnifyVo = new ShapeUnifyVo();
            shapeUnifyVo.setKey(shipBuilderName);
            Integer num = ihsShipBaseMap.get(shipBuilderName).size();
            shapeUnifyVo.setValue(num.toString());
            shapeUnifyVos.add(shapeUnifyVo);
        }

        jsonObject.put("dataList", shapeUnifyVos);
        return jsonObject;
    }

    /**
     * 更新统计渲染表
     *
     * @param reportItemUpdateDto
     * @return
     */
    @Override
    public ReportItem updateReportItem(ReportItemUpdateDto reportItemUpdateDto) {
        ReportItem reportItem = this.getBaseMapper().selectById(reportItemUpdateDto.getId());
        if(reportItem == null){
            throw new ServiceException("统计图表信息异常");
        }
        BeanUtils.copyProperties(reportItemUpdateDto, reportItem);
        this.updateById(reportItem);
        //删除缓存
        redisService.deleteObject(CacheConstants.DATA_BOARD_INFO_KEY+SecurityUtils.getStringUserId()+":"+reportItem.getDataSource());
        return reportItem;
    }

    /**
     * 推送工作台
     *
     * @param id
     */
    @Override
    public void saveWorkbench(Long id) {
        ReportInfo reportInfo = reportInfoMapper.selectById(id);
        if (null != reportInfo) {
            ReportItem reportItem = this.getBaseMapper().selectById(reportInfo.getReportId());
            if (null != reportItem) {
                ReportItemWork reportItemWork = new ReportItemWork();
                reportItemWork.setChartName(reportItem.getChartName());
                reportItemWork.setChartType(reportItem.getChartType());
                reportItemWork.setDataSourceType(reportItem.getDataSourceType());
                reportItemWork.setDataSource(reportItem.getDataSource());
                reportItemWork.setChartSetting(reportItem.getChartSetting());
                reportItemWork.setCreateDate(new Date());
                reportItemWork.setCreateBy(SecurityUtils.getStringUserId());
                reportItemWork.setThemeColor(reportItem.getThemeColor());
                reportItemWork.setChartElement(reportItem.getChartElement());
                reportItemWork.setStatisValueFormat(reportItem.getStatisValueFormat());
                Integer num = reportItemWorkMapper.insert(reportItemWork);
                if (num > 0) {
                    ReportInfoWork reportInfoWork = new ReportInfoWork();
                    reportInfoWork.setStatus(reportInfo.getStatus());
                    reportInfoWork.setCreateDate(reportItemWork.getCreateDate());
                    reportInfoWork.setCreateBy(reportItemWork.getCreateBy());
                    reportInfoWork.setReportId(reportItemWork.getId());
                    reportInfoWork.setChartSort(reportInfo.getChartSort());
                    reportInfoWork.setChartNum(reportInfo.getChartNum());
                    reportInfoWork.setXNum(reportInfo.getXNum());
                    reportInfoWork.setYNum(reportInfo.getYNum());
                    reportInfoWork.setWNum(reportInfo.getWNum());
                    reportInfoWork.setHNum(reportInfo.getHNum());
                    reportInfoWork.setINum(reportInfo.getINum());
                    reportInfoWork.setStaticValue(reportInfo.getStaticValue());
                    Integer reportInfoNum = reportInfoWorkMapper.insert(reportInfoWork);
                    if (reportInfoNum > 0) {
                        reportItem.setWorkbench(1);
                        this.updateById(reportItem);
                    }
                }
            }
        }
    }

    /**
     * 查询工作台
     */
    @Override
    public List<ReportInfoVo> selectWorkbenchs(WorkbenchAllDto workbenchAllDto) {
        List<ReportInfoWork> reportInfos = reportInfoWorkMapper.selectList(new LambdaQueryWrapper<ReportInfoWork>()
                .eq(ReportInfoWork::getCreateBy, SecurityUtils.getStringUserId()));
        List<ReportInfoVo> finalReportInfoVos = new ArrayList<>();
        for (ReportInfoWork reportInfo : reportInfos) {
            ReportInfoVo reportInfoVo = new ReportInfoVo();
            BeanUtils.copyProperties(reportInfo, reportInfoVo);
            ReportItemWork reportItem = reportItemWorkMapper.selectById(reportInfo.getReportId());
            if (null != reportItem) {
                reportInfoVo.setChartName(reportItem.getChartName());
                reportInfoVo.setChartType(reportItem.getChartType());
                reportInfoVo.setDataSourceType(reportItem.getDataSourceType());
                reportInfoVo.setDataSource(reportItem.getDataSource());
                reportInfoVo.setChartSetting(reportItem.getChartSetting());
                reportInfoVo.setThemeColor(reportItem.getThemeColor());
                reportInfoVo.setChartElement(reportItem.getChartElement());
                reportInfoVo.setStatisValueFormat(reportItem.getStatisValueFormat());
            }
            finalReportInfoVos.add(reportInfoVo);
        }
        if (finalReportInfoVos.size() > 0) {
            for (ReportInfoVo finalReportInfoVo : finalReportInfoVos) {
                ReportItemWork reportItem = reportItemWorkMapper.selectById(finalReportInfoVo.getReportId());
                if (null != reportItem) {
                    String dataSource = reportItem.getDataSource();
                    if(dataSource.indexOf("-") > -1){
                        dataSource = dataSource.split("-")[0];
                    }
                    Object object = new Object();
                    if(null==workbenchAllDto.getStartTime() && null == workbenchAllDto.getEndTime()){
                        try {
                            object = this.getTypeContent(dataSource, null, null);
                        } catch (ParseException e) {
                            throw new RuntimeException(e);
                        }
                    }else if(null!=workbenchAllDto.getStartTime() && null != workbenchAllDto.getEndTime()){
                        try {
                            object = this.getTypeContent(dataSource, workbenchAllDto.getStartTime(), workbenchAllDto.getEndTime());
                        } catch (ParseException e) {
                            throw new RuntimeException(e);
                        }
                    }
                    finalReportInfoVo.setDataObject(object);
                }
            }
        }
        return finalReportInfoVos;
    }

    /**
     * LNG船舶建造国家分布
     *
     * @param bo
     * @return
     */
    @Override
    public JSONObject lngShipCountryOfBuild(ItemStatisticsSimpleBo bo) {
        Date startTime = bo.getStartTime();
        Date endTime = bo.getEndTime();
        JSONObject jsonObject = new JSONObject();
        List<ShapeUnifyVo> shapeUnifyVos = new ArrayList<>();

        Map<String, List<IhsShipBase>> ihsShipBaseMap = new HashMap<>();

        if (null != startTime && null != endTime) {
            ihsShipBaseMap = ihsShipBaseService.queryShipBase(startTime,endTime).stream().collect(Collectors.groupingBy(IhsShipBase::getCountryOfBuild));
//            ihsShipBaseMap = ihsShipBaseMapper.selectList(new LambdaQueryWrapper<IhsShipBase>()
//                            .ge(IhsShipBase::getCreateDate, startTime)
//                            .le(IhsShipBase::getCreateDate, endTime))
//                    .stream().collect(Collectors.groupingBy(IhsShipBase::getCountryOfBuild));
        } else if (null == startTime && null == endTime) {
            ihsShipBaseMap = ihsShipBaseService.queryShipBaseList().stream().collect(Collectors.groupingBy(IhsShipBase::getCountryOfBuild));
//            ihsShipBaseMap = ihsShipBaseMapper.selectList(new LambdaQueryWrapper<>()).stream().collect(Collectors.groupingBy(IhsShipBase::getCountryOfBuild));
        }

        for (String shipCountryOfBuildName : ihsShipBaseMap.keySet()) {
            ShapeUnifyVo shapeUnifyVo = new ShapeUnifyVo();
            shapeUnifyVo.setKey(shipCountryOfBuildName);
            Integer num = ihsShipBaseMap.get(shipCountryOfBuildName).size();
            shapeUnifyVo.setValue(num.toString());
            shapeUnifyVos.add(shapeUnifyVo);
        }

        jsonObject.put("dataList", shapeUnifyVos);
        return jsonObject;
    }

    /**
     * LNG船舶船级社分布
     *
     * @param bo
     * @return
     */
    @Override
    public JSONObject lngShipClassificationSociety(ItemStatisticsSimpleBo bo) {
        Date startTime = bo.getStartTime();
        Date endTime = bo.getEndTime();
        JSONObject jsonObject = new JSONObject();
        List<ShapeUnifyVo> shapeUnifyVos = new ArrayList<>();

        Map<String, List<IhsShipBase>> ihsShipBaseMap = new HashMap<>();

        if (null != startTime && null != endTime) {
            ihsShipBaseMap = ihsShipBaseService.queryShipBase(startTime,endTime).stream().collect(Collectors.groupingBy(IhsShipBase::getOrgName));
//            ihsShipBaseMap = ihsShipBaseMapper.selectList(new LambdaQueryWrapper<IhsShipBase>()
//                            .ge(IhsShipBase::getCreateDate, startTime)
//                            .le(IhsShipBase::getCreateDate, endTime))
//                    .stream().collect(Collectors.groupingBy(IhsShipBase::getClassificationSociety));
        } else if (null == startTime && null == endTime) {
            ihsShipBaseMap = ihsShipBaseService.queryShipBaseList().stream().collect(Collectors.groupingBy(IhsShipBase::getOrgName));
//            ihsShipBaseMap = ihsShipBaseMapper.selectList(new LambdaQueryWrapper<>()).stream().collect(Collectors.groupingBy(IhsShipBase::getClassificationSociety));
        }

        for (String shipClassificationSocietyName : ihsShipBaseMap.keySet()) {
            ShapeUnifyVo shapeUnifyVo = new ShapeUnifyVo();
            shapeUnifyVo.setKey(shipClassificationSocietyName);
            Integer num = ihsShipBaseMap.get(shipClassificationSocietyName).size();
            shapeUnifyVo.setValue(num.toString());
            shapeUnifyVos.add(shapeUnifyVo);
        }

        jsonObject.put("dataList", shapeUnifyVos);
        return jsonObject;
    }

    /**
     * LNG船舶经营公司分布
     *
     * @param bo
     * @return
     */
    @Override
    public JSONObject lngShipOperator(ItemStatisticsSimpleBo bo) {
        Date startTime = bo.getStartTime();
        Date endTime = bo.getEndTime();
        JSONObject jsonObject = new JSONObject();
        List<ShapeUnifyVo> shapeUnifyVos = new ArrayList<>();

        Map<String, List<IhsShipBase>> ihsShipBaseMap = new HashMap<>();

        if (null != startTime && null != endTime) {
            ihsShipBaseMap = ihsShipBaseService.queryShipBase(startTime,endTime).stream().collect(Collectors.groupingBy(IhsShipBase::getOperator));
//            ihsShipBaseMap = ihsShipBaseMapper.selectList(new LambdaQueryWrapper<IhsShipBase>()
//                            .ge(IhsShipBase::getCreateDate, startTime)
//                            .le(IhsShipBase::getCreateDate, endTime))
//                    .stream().collect(Collectors.groupingBy(IhsShipBase::getOperator));
        } else if (null == startTime && null == endTime) {
            ihsShipBaseMap = ihsShipBaseService.queryShipBaseList().stream().collect(Collectors.groupingBy(IhsShipBase::getOperator));
//            ihsShipBaseMap = ihsShipBaseMapper.selectList(new LambdaQueryWrapper<>()).stream().collect(Collectors.groupingBy(IhsShipBase::getOperator));
        }

        for (String shipOperatorName : ihsShipBaseMap.keySet()) {
            ShapeUnifyVo shapeUnifyVo = new ShapeUnifyVo();
            shapeUnifyVo.setKey(shipOperatorName);
            Integer num = ihsShipBaseMap.get(shipOperatorName).size();
            shapeUnifyVo.setValue(num.toString());
            shapeUnifyVos.add(shapeUnifyVo);
        }

        jsonObject.put("dataList", shapeUnifyVos);
        return jsonObject;
    }

    /**
     * 根据数据源id获取相关数据
     *
     * @param reportInfoDataDto
     * @return
     */
    @Override
    public ReportInfoDataVo getDataContentById(ReportInfoDataDto reportInfoDataDto) throws ParseException {
        ReportInfoDataVo reportInfoDataVo = new ReportInfoDataVo();
        if(null != reportInfoDataDto.getReportId()){
            ReportItem reportItem = this.getBaseMapper().selectById(reportInfoDataDto.getReportId());
            if(null != reportItem){
                Object object = this.getTypeContent(reportItem.getDataSource(), reportInfoDataDto.getStartTime(), reportInfoDataDto.getEndTime());
                reportInfoDataVo.setDataObject(object);
            }
        }
        return reportInfoDataVo;
    }

    /**
     * 删除工作台数据看板内容
     *
     * @param id
     * @return
     */
    @Override
    public void removeWorkbench(Long id) {
        ReportInfoWork reportInfo = reportInfoWorkMapper.selectById(id);
        if (null != reportInfo) {
            reportInfoWorkMapper.deleteById(reportInfo);
        }
    }

}
